angularjs – 什么是Angular ui-router生命周期? (用于调试静默
发布时间:2020-12-17 09:06:33 所属栏目:安全 来源:网络整理
导读:我找到的最好的是 http://www.ng-newsletter.com/posts/angular-ui-router.html.它不会像例如,$ stateChangeStart,exampleState.onEnter,exampleState.resolve和exampleState.templateProvider火的顺序那么深。 一个伟大的答案格式将是干净的。就像是:
我找到的最好的是
http://www.ng-newsletter.com/posts/angular-ui-router.html.它不会像例如,$ stateChangeStart,exampleState.onEnter,exampleState.resolve和exampleState.templateProvider火的顺序那么深。
一个伟大的答案格式将是干净的。就像是: >状态foo的初始页面加载: >角生命周期步骤1 > State change foo – >酒吧 > $ stateChangeStart event fires >嵌套状态 谢谢! 编辑:调试功能提供足够的洞察力以满足需要。参见我的answer below的代码片段。
经过一些实验,我想出了如何看到生命周期足够好,调试我的应用程序,并得到一个感觉发生了什么。使用所有事件,包括onEnter,onExit,stateChangeSuccess,从
here的viewContentLoaded,给了我一个体面的图片,当事情发生时,一个更加灵活和特定于我的代码比写出的生命周期。在应用程序模块的“运行”功能中,我放置:
这个代码会节省我的时间和困惑,如果我开始使用它,当我第一次使用Angular和UI路由器。 UI路由器需要一个“调试”模式,默认情况下启用它。 $rootScope.$on('$stateChangeStart',function(event,toState,toParams,fromState,fromParams){ console.log('$stateChangeStart to '+toState.name+'- fired when the transition begins. toState,toParams : n',toParams); }); $rootScope.$on('$stateChangeError',fromParams,error){ console.log('$stateChangeError - fired when an error occurs during transition.'); console.log(arguments); }); $rootScope.$on('$stateChangeSuccess',fromParams){ console.log('$stateChangeSuccess to '+toState.name+'- fired once the state transition is complete.'); }); $rootScope.$on('$viewContentLoading',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',unfoundState,fromParams){ console.log('$stateNotFound '+unfoundState.to+' - fired when a state cannot be found by its name.'); console.log(unfoundState,fromParams); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |