Getting Result of $q's Resolution or Rejection
- by Kevin Meredith
I'm looking at a $q example from Mastering Web Application Development with Angular.
For this code, how can I retrieve the String result of pizzaOrderFulfillment.resolve(...) or pizzaOrderFulfillment.reject?
var myApp = angular.module('myApp',[]);
myApp.controller("MyCtrl", function ($scope, $q) {
var Person = function(name) {
this.eat = function(food) {
return name + " is eating " + food;
};
this.beHungry = function(reason) {
return name + " is hungry because" + reason;
};
};
// success
var pizzaOrderFulfillment = $q.defer();
var pizzaDelivered = pizzaOrderFulfillment.promise;
var man = new Person("man");
pizzaDelivered.then(man.eat, man.beHungry);
pizzaOrderFulfillment.resolve("chicken");
// TODO: var successResult = "man is eating chicken"
});