我的路由器配置如下:
.state('home.view-profile', {
url: '/view-profile/:profileUrl',
template: '<view-profile input="$resolve.profileData"></view-profile>',
title: 'View Profile',
resolve: {profileData: function(artistService, $stateParams){
return artistService.getArtist($stateParams.profileUrl).then((data) => {
const timer = new Date();
console.log(timer.getSeconds() + ':' + timer.getMilliseconds());
console.log(data.data.artist);
return data.data.artist;
});
}
}
})
和组件
module.component('view-profile', {
templateUrl: 'view-profile/view-profile.component.html',
bindings: {
input: '='
},
controller: ['$state', '$scope', '$stateParams', function ($state, $scope, $stateParams) {
const model = this;
console.log('***************');
console.log(model.input);
}]
});
我可以看到 data.data.artist
是有效的,并且在解析过程中可以从日志中访问,但在组件内部,input
始终未定义
J 只是不明白为什么会发生这种情况?
最佳答案
抱歉并感谢您的帮助!
我刚刚发现这个问题。在我们的多开发人员工作流程中,ui-router 的版本以某种方式降级了。一些开发人员安装了 0.2.1
而不是最新的 0.3.x
,我合并了,这就是问题所在。
只有 0.3.x
路由器支持将 $resolve.param
发送到组件绑定(bind)。
升级后 - 一切正常。只是我的自信心受到了伤害......
关于javascript - Angular UI 路由器 - 解析后无法在组件中获取我的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39196795/