Using ngRoute once can hook up in event: $routeChangeStart
and do different actions ...
使用ngRoute可以在事件中挂钩:$ routeChangeStart并执行不同的操作......
app.run(function ($rootScope, $location) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
................
Is it possible to achieve the same using UI-Router?
使用UI-Router可以实现相同的功能吗?
2 个解决方案
#1
12
Yes it's possible:
是的,这是可能的:
$rootScope.$on("$stateChangeStart",
function (event, toState, toParams, fromState, fromParams) {
#2
1
Or just use
或者只是使用
$scope.$on("$stateChangeStart",...);
If you want this to be triggered on a single page.
如果您希望在单个页面上触发此操作。
#1
12
Yes it's possible:
是的,这是可能的:
$rootScope.$on("$stateChangeStart",
function (event, toState, toParams, fromState, fromParams) {
#2
1
Or just use
或者只是使用
$scope.$on("$stateChangeStart",...);
If you want this to be triggered on a single page.
如果您希望在单个页面上触发此操作。