Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS UI-Router event when changing route

Using ngRoute once can hook up in event: $routeChangeStart and do different actions ...

 app.run(function ($rootScope, $location) {
    $rootScope.$on("$routeChangeStart", function (event, next, current) {
    ................

Is it possible to achieve the same using UI-Router?

like image 433
David Dury Avatar asked Apr 11 '15 21:04

David Dury


2 Answers

Yes it's possible:

$rootScope.$on("$stateChangeStart",
    function (event, toState, toParams, fromState, fromParams) {
like image 78
karaxuna Avatar answered Nov 19 '22 11:11

karaxuna


Or just use

$scope.$on("$stateChangeStart",...);

If you want this to be triggered on a single page.

like image 1
Petru Avatar answered Nov 19 '22 11:11

Petru