【发布时间】:2017-01-04 22:14:22
【问题描述】:
我有一个这样配置的路由器:
.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 始终是undefined
J只是不明白为什么会这样?
【问题讨论】:
-
也许你应该将
$resolve注入你的控制器 -
我试过了,但没有任何有意义的数据..
标签: javascript angularjs angular-ui-router angular-components