【问题标题】:Angular 1.5.x Component Router Resolve (2)Angular 1.5.x 组件路由器解析(2)
【发布时间】:2017-01-14 11:32:08
【问题描述】:

如何让组件路由在执行控制器和渲染视图之前等待数据。类似于ngRouteui-router 中的resolve

文档有这个:

这只是等待url改变,例如:

//Old url
http://localhost/#/

// wait the promise (eg 1s) and then change the url to
http://localhost/#/heroes

但是在点击链接后立即改变了视图,然后改变了url,太奇怪了!

这不会阻止视图渲染或控制器执行(显然)。

这种情况的演示:

代码和预览:plunkr.co(点击英雄)

有一个类似的问题没有答案:Angular 1.5.x Component Router Resolve

【问题讨论】:

    标签: javascript angularjs angular-component-router angular-components


    【解决方案1】:

    我找到了解决办法:

    这应该在组件定义中配置:

    .component('myComponent', {
        templateUrl: './my-compnent.html',
        controller: MyComponentCtrl,
        $canActivate: function($nextInstruction, $prevInstruction) {
          return Promise.resolve(<true or false>);
        }
    })
    

    【讨论】:

      猜你喜欢
      • 2016-09-19
      • 2017-10-19
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 2016-08-09
      • 2017-03-02
      相关资源
      最近更新 更多