Hi I have a code like following in my controller
myClientApp.controller('ListCtrl', function ($scope,$http,$cookieStore,$location, $routeParams) {
var data = {
"menus": {
"view": true,
"add": true,
"update": true,
"delete": true
},
"linkInfo": {
"labelColumn": "codeName",
"linkColumn": "lookupKey",
"urlInfo": "reference"
},
"resultList": [
"{\"lookupKey\":2,\"clientKey\":1,\"codeName\":\"Application.AppType\",\"codeValue\":\"ApplicationType2\",\"codeDesc\":\"##\",\"updatedBy\":null,\"internalCodeName\":\"Application.AppType\"}",
"{\"lookupKey\":3,\"clientKey\":1,\"codeName\":\"Application.Class\",\"codeValue\":\"Tier 1\",\"codeDesc\":\"Critical Application requiring immediate response in case of a disruption of Service\",\"updatedBy\":null,\"internalCodeName\":\"Application.Class\"}"
]
};
$scope.result = angular.fromJson(data.resultList);
alert($scope.result[0].codeName);
});
And It gives me undefined . Why?
Because resultList is an array of JSON strings, not a single JSON string; you need to specify which key you want to decode:
$scope.result = [
angular.fromJson(data.resultList[0]),
angular.fromJson(data.resultList[1])
];
alert($scope.result[0].codeName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With