Json Parsing Error In Angularjs When Getting From Server But Not When Static
I have this plunker: http://plnkr.co/edit/FnCTfZf8RVBx2WVscyK8?p=info if I change the line/s(around 23) app.controller('MainCtrl', function($scope) { $scope.links = [...]; });
Solution 1:
The issue you are facing is different reference of variables. i.e when you say
a = b
Then when you modify "b", "a" is not going to change. Hence, in ng-init you have just initialized with value
submenu = links
When "links" gets updated then "submenu" does not.
So, here you can setup watch on scope variable "links", which when updated you can update "submenu".
Please find the plunkr for the same.
Code:
$scope.$watch('links',function(newValue){
$scope.submenu=newValue;
});
Post a Comment for "Json Parsing Error In Angularjs When Getting From Server But Not When Static"