Passionate Engineer
Passionate Engineer

Reputation: 10412

Angular deferred promise

I have a function that returns deferred promise in Angular.

I have used $$state to access its values from calling class but not sure if this is the right way.

Should I use .then instead or is there any standard way to access a specific variable for $q.deferred Promise object?

Upvotes: 1

Views: 594

Answers (1)

Davin Tryon
Davin Tryon

Reputation: 67296

Yes, you should not be accessing $$state directly. Use a .then to define a callback that will have the data passed to it.

For example:

var promise = service.getDefferredPromise();

promise.then(function(data) {
   //use the data
   $scope.something = data.something;
});

Upvotes: 1

Related Questions