0

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?

4
  • It would be great if you could provide your HTML code as well. Commented May 27, 2016 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.. Commented May 27, 2016 at 10:28
  • It seems it problem related to your your JSON response, not on angular front. Commented May 27, 2016 at 10:38
  • So the data should be sent differently from WordPress API rather than changed by angular? Commented May 27, 2016 at 10:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.