$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;
}
});
我想将上述代码从ng-route更改为ui-router。我将其他人更改为stateProvider和stateParams,但不知道$ routeChangeSuccess将如何更改为$ stateChangeSucess?
答案 0 :(得分:2)
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams){ ... })
答案 1 :(得分:2)
$stateChangeSuccess
代替$routeChangeSuccess
$stateChangeStart
- 过渡开始时被解雇。
$rootScope.$on("$stateChangeSuccess", function () {
});
答案 2 :(得分:0)
是的,$ stateChangeSuccess。从这里查看更多内容https://github.com/angular-ui/ui-router/wiki
答案 3 :(得分:0)
$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将提供更改的网址,并可以执行与此相关的操作。