Javascript 角度1.5.x组件路由器分辨率(2)
如何使组件路由在执行控制器和渲染视图之前等待数据。类似于Javascript 角度1.5.x组件路由器分辨率(2),javascript,angularjs,angular-component-router,angular-components,Javascript,Angularjs,Angular Component Router,Angular Components,如何使组件路由在执行控制器和渲染视图之前等待数据。类似于ngRoute和ui路由器的resolve 该文件包含以下内容: 这仅等待url更改,例如: //Old url http://localhost/#/ // wait the promise (eg 1s) and then change the url to http://localhost/#/heroes 但是点击链接后视图立即改变,然后url也改变了,真奇怪 这不会阻止视图渲染或控制器执行(显然) 这种情况的演示: 编码和预
ngRoute
和ui路由器的resolve
该文件包含以下内容:
这仅等待url更改,例如:
//Old url
http://localhost/#/
// wait the promise (eg 1s) and then change the url to
http://localhost/#/heroes
但是点击链接后视图立即改变,然后url也改变了,真奇怪
这不会阻止视图渲染或控制器执行(显然)
这种情况的演示:
编码和预览:(点击英雄)
还有一个类似的问题没有答案:我找到了一个解决方案:
这应该在组件定义中配置:
.component('myComponent', {
templateUrl: './my-compnent.html',
controller: MyComponentCtrl,
$canActivate: function($nextInstruction, $prevInstruction) {
return Promise.resolve(<true or false>);
}
})
.component('myComponent'{
templateUrl:“./my compent.html”,
控制器:MyComponentCtrl,
$canActivate:function($nextInstruction,$prevInstruction){
返回承诺。解决();
}
})
我找到了一个解决方案:
这应该在组件定义中配置:
.component('myComponent', {
templateUrl: './my-compnent.html',
controller: MyComponentCtrl,
$canActivate: function($nextInstruction, $prevInstruction) {
return Promise.resolve(<true or false>);
}
})
.component('myComponent'{
templateUrl:“./my compent.html”,
控制器:MyComponentCtrl,
$canActivate:function($nextInstruction,$prevInstruction){
返回承诺。解决();
}
})