栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

链承诺与AngularJS

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

链承诺与AngularJS

通过添加自己的承诺使所有方法变得原子化。在您的代码中,第一个

resolve
将完成整个请求。

如果这些方法有自己的承诺,则可以轻松地将它们链接起来。

angular.module('deps-app.payment.services', []).factory('paymentStrategy', function($q) {var ITEM_TO_PURCHASE = "test.beer.managed";_init = function() {  return $q(function (resolve, reject) {    inappbilling.init(resolve, reject, { showLog: true });   });};_purchase = function() {  return $q(function (resolve, reject) {    inappbilling.buy(resolve, reject, ITEM_TO_PURCHASE);    });};_consume = function() {  return $q(function (resolve, reject) {    inappbilling.consumePurchase(resolve, reject, ITEM_TO_PURCHASE);  });};return  {  // In this case, you don't need to define a additional promise,   // because placing a return in front of the _init, will already return   // the promise of _consume.  buy: function() {        return _init()      .then(_purchase)        // remove () from inside the callback, to pass the actual method       // instead the result of the invoked method.      .then(_consume);        }    };

});



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382941.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号