当前位置: 首页 > 面试题库 >

什么是Angular ui路由器生命周期?(用于调试静默错误)

仲孙思源
2023-03-14
问题内容

我发现的最好的是http://www.ng-newsletter.com/posts/angular-ui-
router.html
。它不会去深,例如,在该命令$stateChangeStartexampleState.onEnterexampleState.resolve,和exampleState.templateProvider火灾。

一个很好的答案格式将是干净的。就像是:

  1. 状态foo的初始页面加载:

    1. 角生命周期步骤1
    2. UI路由器生命周期步骤1
    3. UI路由器生命周期解决
    4. UI路由器生命周期onEnter触发
    5. 角生命周期步骤2
    6. 状态更改 foo- > bar

    7. $stateChangeStart 事件引发

    8. foo onExit
    9. bar onEnter火灾
    10. templateUrl 获取模板
    11. UI路由器在摘要循环(或任何位置)中重新插入Angular生命周期。
    12. 嵌套状态
  2. 多个命名视图:

  3. 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);
});


 类似资料:
  • 'static 生命周期在可能存在的生命周期中是最长的,并在运行程序的周期中持续存在。static 生命周期也可能被强制转换成一个更短的生命周期。有两种方式使变量拥有 static 生命周期,这两种方式都是保存在可执行文件的只读内存区: 使用 static 声明来产生常量(constant)。 产生一个拥有 &'static str 类型的 string 字面量。 看下面的例子,了解列举到的各个方

  • 我对Spring的生命周期感到困惑。 上面的代码片段是否创建了对象? 如果上述答案为真。 a) 然后,对于作用域为“singleton”的bean,获取在上述代码片段中创建的对象。我是对还是错? b)对于范围为“原型”的情况,创建的对象是否未使用。因为,容器总是返回新对象。 上面的代码片段是否创建了对象? 如果答案是假的, Spring框架如何验证bean定义是否正确。 根据亨利的回答 通常,单例

  • TestInstancePostProcessor defines the API for Extensions that wish to post process test instances. Common use cases include injecting dependencies into the test instance, invoking custom initializatio

  • 我对铁锈寿命的学习过程如下(基于铁锈书): 我想注释,当引用后面的值超出范围时 通常(并不总是!请参阅. data部分,即'静态')值位于块中 我们注释像这样的块,例如结构字段像 。 在哪一点上我的理解是错误的?提前感谢你对我的宽容。 免责声明:

  • 本文向大家介绍本地存储的生命周期是什么?相关面试题,主要包含被问及本地存储的生命周期是什么?时的应答技巧和注意事项,需要的朋友参考一下 : 和 都能控制数据的存储时间。 是一个绝对的过期时间, 是文档被访问之后的存活时间(是相对时间)。默认是 。 : 当会话被关闭后(浏览器、标签页被关闭),就会被清除。与 用法一样。 : 除非被主动清除,不然永久储存在浏览器中。 : 没有过期时间,除非主动清除。

  • Cocos Creator 为组件脚本提供了生命周期的回调函数。用户只要定义特定的回调函数,Creator 就会在特定的时期自动执行相关脚本,用户不需要手工调用它们。 目前提供给用户的生命周期回调函数主要有: onLoad start update lateUpdate onDestroy onEnable onDisable onLoad 组件脚本的初始化阶段,我们提供了 onLoad 回调函数