In the rootScope of my project i have defined a function that realizes an $http call.
angular.module('rsa',['ngRoute', 'ngCookies', 'ngMaterial'])
.config(function($routeProvider, $httpProvider){
$routeProvider.when('/chapters', {
...
});
$routeProvider.when('/themes', {
...
});
// ... more routes
$routeProvider.otherwise('/home');
})
.controller(...)
.run(['$rootScope', 'UserService', '$location', '$cookies','$http', '$q',
function(rootScope, UserService, location, cookies, http, $q){
rootScope.isAdmin = function(){
return $http.get('/isAdmin').then(function(resp){...}, function(resp)
{...})
}
}])
rootScope's isAdmin
method causes an infinite digest loop error.
Meanwhile, the same $http call (from isAdmin methods) works well inside other controllers.
I've read a little about what can be the problem and i found out that the $http service calls the $apply to force the $digest cycle but i don't understand what happens exactly with the $http service that drove me to get the following result in the console.
This is th html snippet:
<a class = "navbar-brand" href="#/admin" ng-if="isAdmin()"> Administration </a>
Q1: Why is $http.get() causing an infinite number of $digest cycles.
Q2: Why does it only happen on rootScope and not in any other scope.
BTW xhr syncronous work fine and i am using angular 1.6.4