Answer the question
In order to leave comments, you need to log in
AngularJS $scope
There is a controller:
angular.module('jsRouter.controllers', [])
.controller('router', ['$rootScope', function($rootScope){
$rootScope.isExistRoute = function (route){
return $rootScope.routes[route] !== 'undefined'? true: false;
};
}])
.run(['$rootScope', 'loadRoutes', function ($rootScope, loadRoutes){
loadRoutes.get().then(function (response){
$rootScope.routes = response.data;
});;
}]);
angular.module('jsRouter.directives',[])
.directive('routerHref', ['$rootScope', function ($rootScope){
return {
restrict: 'A',
replace: true,
scope: true,
link: function ($scope, element, attrs){
console.log($scope.$parent);
}
};
}]);
Scope {$id: "002", $$childTail: $$childScopeClass, $$childHead: $$childScopeClass, $$prevSibling: null, $$nextSibling: null…}
$$asyncQueue: Array[0]
$$childHead: $$childScopeClass
$$childScopeClass: function () {
$$childTail: $$childScopeClass
$$destroyed: false
$$isolateBindings: Object
$$listenerCount: Object
$$listeners: Object
$$nextSibling: null
$$phase: null
$$postDigestQueue: Array[0]
$$prevSibling: null
$$watchers: null
$id: "002"
$parent: null
$root: Scope
routes: Array[5]
this: Scope
__proto__: Scope
Answer the question
In order to leave comments, you need to log in
Most likely, this array of routes is obtained from the server, and at the very moment when console.log($scope.$parent.routes) is triggered, it does not matter yet. In the first case, by the time you view the object displayed in the console, it has time to load.
But again, this is just a guess. The overall picture can be assessed by looking at the entire code and not at a specific passage.
If you have things like "$scope.$parent" then you are clearly doing something wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question