Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm new to JS/AngularJS (using V1.3.0)

I am making an API call using WP API (wordpress api) to return JSON in Angular. The app is almost working as I want, but I use a value selected from one JSON call to filter another JSON file using a ng-repeat. It is wokring as should apart from when the value has a special character in (ampersand, apostrophe, full stop, foreign letter etc) I'm guessing I need to parse/sanatize the JSON first? Here is an example of the characters being sent:

Anderson's
COMME DES GAR\u00c7ONS
DOLCE & GABBANA

I use this in my factory to get brands:

function getBrands(arg) {
  return ($http.get(url + 'designers?filter[meta_key]=alpha&filter[meta_value]=' + arg + '&filter[posts_per_page]=200').then(handleSuccess, handleError));
}

Controller:

$scope.changeBrand = function(){
    wpFactory.getBrands($scope.radioValue).then(function (succ) {
    $scope.brands = succ;
    angular.forEach(succ, function(value, index) {
        $scope.setUrlForImage(index, value.featured_image);
    });
    }, function(err) {
    console.log('Error: ', err);
});

HTML

 <div ng-init="my = {Variable: ''}" >

    <div ng-repeat="myVar in brands" ng-init="my.Variable=myVar" >
    </div>
    <ul class="media-list">
        <li ng-repeat="post in posts | filter: { acf: { store_brands: my.Variable.title.rendered } }">
         <div class="media-body">
              <a href="{{post.acf.store_url}}" target="_blank">
                <h4 class="media-heading">{{post.title.rendered}}</h4>
              </a>
            </div>
        </li>
    </ul>
</div>

I have seen ng-bind-html used, but how do I pre format the JSON for use in ng-repeat and as dynamic filter values?

share|improve this question
    
It would be great if you could provide your HTML code as well. – Satyaki May 27 at 10:19
    
I've added the html, basically trying to grab a value from brands JSON and filter against and value in posts JSON. Working apart from when special characters are involved.. – pdg87 May 27 at 10:28
    
It seems it problem related to your your JSON response, not on angular front. – Satyaki May 27 at 10:38
    
So the data should be sent differently from WordPress API rather than changed by angular? – pdg87 May 27 at 10:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.