Issue
This is my output
{"contacts":[{"id":"1","company":"Cutting","contact":"Russell Chimera"},{"id":"2","company":"Gge\'s","contact":"Marci"}]}
I got this error
SyntaxError: Unexpected token ' in JSON at position 97 at JSON.parse
I tried to print it like {{x.company}}
or {{x.company | escape}}
but problem remain same. I try to print company name "Gge's"
. I don't want to remove single quote from company name.
Can anyone please help me to find solution?
Solution
Your scope variable x
should hold the value of data.contacts[1]
, to get the value of Gge's
with single quote from company name. There is no such scenario in AngularJS where it omits the single quote from the JSON value. Be sure of your JSON again.
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
var data = {
"contacts":[
{
"id":"1","company":"Cutting","contact":"Russell Chimera"
},
{
"id":"2","company":"Gge\'s","contact":"Marci"
}
]
};
$scope.x = data.contacts[1];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
{{x.company}}
</div>
Answered By - Ankit Agarwal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.