huan feng
huan feng

Reputation: 8623

Is there any event before $locationChangeStart?

I want to re-init a service variable before every page loaded. It seems $locationChange cannot match this needs in some condition

angular.module('xxx')
...
.service('xxxsvc', [..., function(){
    var groups = {};
}

$rootScope.on('$locationChange', function(){
    groups = {}
});
}]);

I used serveral directive on the page use this service, it seems $locationChange isn't executed before all directives. I want to re-init or clear the variable before any part of page is initialized.

Does anyone can help on this?

Upvotes: 1

Views: 218

Answers (1)

Ilya Chernomordik
Ilya Chernomordik

Reputation: 30265

As far as I know there is stateChangeStart and since you can even cancel it during the operation, nothing else should happen before it. But I see that you use '$locationChange' and not '$stateChangeStart', maybe that is the issue?

You can read about $stateChangeStart here.

Another possible problem, did you verify that your service is called at all? The controller initialize is usually not called again unless you force it.

Upvotes: 1

Related Questions