Fabic
Fabic

Reputation: 508

Ionic/Angular alternative to $stateChangeStart

I was wondering if there is an alternative to

$rootScope.$on("$stateChangeStart", function() {});

Because I want to get that event on many pages which do different things. If I use the way above, this event is fired for every page I implemented it (even if the page wasn't where I came from or wasn't where I go to)...which is a little overheading.

So what I am looking for is an event which is fired only if the controller is used on the current page.

Upvotes: 0

Views: 1059

Answers (2)

Rui李
Rui李

Reputation: 39

use $stateChangeStart instead of $routeChangeStart

there are some differences between Angularjs ngRoute and ui-router.

http://www.amasik.com/angularjs-ngroute-vs-ui-router/

Upvotes: 2

chapinkapa
chapinkapa

Reputation: 2653

Sure. Just use the event $routeChangeStart:

$scope.$on('$routeChangeStart', function(){
  console.log(arguments);
});

Upvotes: 0

Related Questions