我发现的最好的是http://www.ng-newsletter.com/posts/angular-ui- router.html。它不会去深,例如,在该命令$stateChangeStart,exampleState.onEnter,exampleState.resolve,和exampleState.templateProvider火灾。
$stateChangeStart
exampleState.onEnter
exampleState.resolve
exampleState.templateProvider
一个很好的答案格式将是干净的。就像是:
状态foo的初始页面加载:
状态更改 foo- > bar
$stateChangeStart 事件引发
onExit
onEnter
templateUrl
多个命名视图:
ui-sref单击
等等…谢谢!
经过一些试验,我弄清楚了如何充分了解生命周期,以调试我的应用程序并了解正在发生的事情。使用所有事件(包括onEnter,onExit,stateChangeSuccess和此处的 viewContentLoaded),可以使我对事件的发生情况有一个体面的了解,这种方式对代码的灵活性和针对性比书面生命周期更加灵活和具体。在应用程序模块的“运行”功能中,我放置了:
如果我第一次使用Angular和UI-router时就开始使用它,那么这段代码将节省我很多时间和混乱。UI路由器需要“调试”模式,默认情况下启用此功能。
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){ console.log('$stateChangeStart to '+toState.name+'- fired when the transition begins. toState,toParams : \n',toState, toParams); }); $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams, error){ console.log('$stateChangeError - fired when an error occurs during transition.'); console.log(arguments); }); $rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){ console.log('$stateChangeSuccess to '+toState.name+'- fired once the state transition is complete.'); }); $rootScope.$on('$viewContentLoading',function(event, viewConfig){ console.log('$viewContentLoading - view begins loading - dom not rendered',viewConfig); }); /* $rootScope.$on('$viewContentLoaded',function(event){ // runs on individual scopes, so putting it in "run" doesn't work. console.log('$viewContentLoaded - fired after dom rendered',event); }); */ $rootScope.$on('$stateNotFound',function(event, unfoundState, fromState, fromParams){ console.log('$stateNotFound '+unfoundState.to+' - fired when a state cannot be found by its name.'); console.log(unfoundState, fromState, fromParams); });