Reputation: 198
I have an HTML element that have value attribute. The value should be Comfort & Protection but the name that comes from the JSON get result is Comfort &
Protection and AngularJS is printing it like this on my view.
I try to put this name inside an html element value attribute.
<div ng-app="app">
<div ng-controller="ExampleCtrl">
<input type="text" ng-repeat="type in types" value="{{type.name}}" />
</div>
</div>
var app = angular.module("app", []);
app.controller('ExampleCtrl', function($scope){
$scope.types = [
{
id: 1,
name: 'Comfort & Protection'
},
{
id: 2,
name: 'Other Name'
}
]
})
http://codepen.io/Fclaussen/pen/vOXNbg
Upvotes: 3
Views: 6439
Reputation: 198
Managed to solve the problem based on Max Zoom answer.
I created a filter to filter ampersands, like this.
app.filter('ampersand', function(){
return function(input){
return input ? input.replace(/&/, '&') : '';
}
});
And on my View I changed from {{term.name}}
to {{term.name | ampersand}}
Upvotes: 2
Reputation: 7743
One option would be to replace the &
string with &
as below:
var text = name.replace(/&/g, '&')
Upvotes: 4