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?