When working with a parent view and a child view, I encounter an issue with accessing a json file. In the parent view, I retrieve the json file using the following code:
$scope.services = Services.query();
factory('Services', function($resource) {
return $resource('/services/:serviceId', {
serviceId: '@_id'
}, {});
Initially, everything works fine as I can display the content of the json file in the view using ng-repeat. However, problems arise when trying to access the child view directly or refreshing the page. Despite being able to show the content in the view, I face difficulties using the file in the child controller. To troubleshoot this issue, I added the following code snippet to the child:
if($scope.services){ // in both cases it's not null
var s="";
if($scope.selectedService)
s="NO refresh an NO direct access";
else
s="refresh or direct access";
console.log(s);
console.log("data : " + $scope.services);
console.log($scope.services.length);
console.log($scope.services)
}
The output reveals some inconsistencies that lead me to believe the child controller may be executing before the parent controller. How can I resolve this problem?