Reputation: 902
$scope.$on("$routeChangeSuccess", function (event, next, current) {
switch (next.originalPath) {
case "/ac" :
$scope.currentTab = 1;
break;
case "/bp/:type?/:tab?":
$scope.currentTab = 2;
break;
case "/bs":
$scope.currentTab = 3;
break;
default :
$scope.currentTab = 1;
break;
}
});
I want to change the above code from ng-route to ui-router. I changed others to stateProvider and stateParams but no idea about how the $routeChangeSuccess will change is it to $stateChangeSucess?
Upvotes: 0
Views: 1572
Reputation: 902
$scope.$on("$stateChangeSuccess", function (event, toState, toParams, fromState, fromParams) {
switch ( toState.url ) {
case "/ac" :
$scope.currentTab = 1;
break;
case "/bp":
$scope.currentTab = 2;
break;
case "/bs":
$scope.currentTab = 3;
break;
default :
$scope.currentTab = 1;
break;
}
});
toState.url will give the changed url and can do actions related to that.
Upvotes: 0
Reputation: 186
yes, $stateChangeSuccess. See more from here https://github.com/angular-ui/ui-router/wiki
Upvotes: 0
Reputation: 133403
You should use $stateChangeSuccess
instead of $routeChangeSuccess
as per State Change Events.
$stateChangeStart
- fired when the transition begins.
$rootScope.$on("$stateChangeSuccess", function () {
});
Upvotes: 2
Reputation: 1480
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams){ ... })
Upvotes: 2