forgottofly forgottofly - 6 months ago 9
Javascript Question

Parse name from the object and display-Angular Js

My object(Unparsed and raw):

$scope.result= {
"id": 2360,
"subject": "Meeting Postponed Status",
"message": "{\"name\":\"Riana\",\"status\":\"Postponed\",\"meeting\":\"Approval No 342\",\"postponedDate\":\"2015-06-24 18:30:00\",\"postponedTime\":\"13:02:57\"}",
"modifiedDate": "2015-06-29 17:09:59",
"categoryId": 1,
}


I'm parsing the property
message
of
$scope.result
object as

$scope.result=JSON.parse($scope.result.message);
which outputs
$scope.result.message
as

$scope.result.message={"name":"Riana","status":"Postponed","meeting":"Approval No 342","postponedDate":"2015-06-24 18:30:00","postponedTime":"13:02:57"}


But if I want to bind the name
Riana
I'm not able to do it in the HTMl
I tried by giving {{result.message.name}} but not able to render the name.
Is there a way to parse in the HTML as I'm unable to do it in the controller?

Answer

You need to assign the JSON.parse($scope.result.message) to $scope.result.message.

E.g.

$scope.result.message = JSON.parse($scope.result.message);

Here's the JsFiddle link.

Hope it helps.

Comments