Angular 组件解析绑定已定义

Angular component resolve binding is defined

我有一个实例化 Restangular 对象的控制器。

Restangular.one('doctors', profile_id).get().then(function(resp) {
  $scope.doctor = resp;
})

我还有一个组件想要等待 $scope.doctor 在它被实例化之前被定义。我怎样才能确保医生被定义?

app.component('doctorReviews', {
  bindings: {
    doctor: '='
  },
  controller: function() {

    var self = this;

    this.doctor.getList('reviews').then(function(resp) {
      self.reviews = _.sortBy(resp, 'separation')
    })

  }
})

您可以在页面模板中添加 ng-if='doctor != null' 以确保 doctorReviewsdoctor 定义后初始化:

//somewhere in your page html...
<doctor-reviews ng-if='doctor != null'></doctor-reviews>