I found an interesting example involving $q
on the book Mastering Web Application Development with Angular.
In this code snippet, I am curious about how to obtain the String result of either
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"
});