i have tree created dynamically json.there 1 controller , in controller there json array.i use json create tree,but need read json file externally.
my controller;
.......... $scope.myjson = { "option1": [ { "child":[{"label":"test1" },{"label":"test2"}], "id": "option1" } ], "option2": [ { "child":[{"label":"test1.1",}], "id": "option2" } ], ........... }
json array reading part(in controller);
angular.foreach($scope.myjson, function(value, key) { if (key === 'option1') { for(var t=0;t<$scope.myjson[key][0].child.length;t++) { ......somethings......... } }
i want call json file , read create tree.how can call json file , read in angularjs?
reading json in angular pretty straightforward $http. keep in mind $http return promise, , need resolve before processing.
here sample code:
$http.get('assets/messages.json').then(function (data) { /** work data **/ });