Getting Result of $q's Resolution or Rejection
Posted
by
Kevin Meredith
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Meredith
Published on 2014-05-31T14:27:02Z
Indexed on
2014/05/31
15:26 UTC
Read the original article
Hit count: 210
JavaScript
|angularjs
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"
});
© Stack Overflow or respective owner