angularjs - Broadcast event when state loaded and controllers are initiated -


i need broadcast event when state loaded , controllers initiated. i'm using angularjs v1.3.15 , ui-router v0.2.11.

i'm trying use $statechangesuccess event, controller doesn't grab broadcasted event, because hasn't been iniatated when event broadcasted.

in module run method have:

$rootscope.$on('$statechangesuccess', function (event) {     $rootscope.$broadcast('someevent'); }); 

my controller has following:

$scope.$on('someevent', function () {     $scope.getlist(); }); 

i tried using $viewcontentloading , $viewcontentloaded because have nested controllers/views, fires multiple times, $scope.getlist() runs multiple times.

any solution problem?

in case there no need put statechange listener. angular ui-router provide feature use case: resolving controller on state change see ui-router on github. further more should use service returning promise, since api call async, , inject service in controller. see "resolve" section on same page answers needs.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -