Search code examples
angularjsrestangular

Angular component resolve binding is defined


I have a controller that instantiates a Restangular object.

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

I also have a component that would like to wait for $scope.doctor to be defined before it is instantiated. How can I ensure doctor is defined?

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

    var self = this;

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

  }
})

Solution

  • you could add ng-if='doctor != null' in your page template to ensure doctorReviews initialized after doctor defined:

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