0

我有一个这样配置的路由器:

.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 只是不明白为什么会发生这种情况?

4

2 回答 2

1

抱歉,感谢您的帮助!我刚刚发现了这个问题。在我们的多开发人员工作流程中,ui-router 的版本以某种方式降级。一些开发人员安装0.2.1而不是最新的0.3.x,我合并了,这就是问题所在。只有0.3.x路由器支持发送$resolve.param到组件绑定。
升级后 - 一切正常。只有我的自信心受到伤害...

于 2016-08-31T10:17:29.650 回答
0

您是否尝试过解决控制器中的承诺?

model.input.then(function(res) { console.log(res); }
于 2016-08-29T02:14:37.690 回答