我正在嘗試在Angularjs中調用服務方法。服務方法稱爲好,但是IT不會將任何值返回給在控制器中調用它的函數。
如果有人能幫助我,我會很高興。這是我的代碼波紋管。
logosStreams.factory("processPaypal", ['$http', '$timeout', '$q', '$state',function($http, $timeout, $q, $state){
var transCall = {};
var transcallPromise2 = $q.defer();
return {
onSuccesfulPayment: function(payment) {
console.log("payment success: " + JSON.stringify(payment, null, 4));
transcallPromise2.resolve(payment);
},
onAuthorizationCallback: function(authorization) {
console.log("authorization: " + JSON.stringify(authorization, null, 4));
//return authorization;
},
createPayment: function(data) {
// for simplicity use predefined amount
var paymentDetails = new PayPalPaymentDetails("0", "0", "0");
var payment = new PayPalPayment(data.amt, "USD", data.name, "Sale",
paymentDetails);
return payment;
},
buyInFutureBtn : function(e) {
// future payment
PayPalMobile.renderFuturePaymentUI(this.onAuthorizationCallback, this.onUserCanceled);
},
profileSharingBtn : function(e) {
// profile sharing
PayPalMobile.renderProfileSharingUI(["profile", "email", "phone","address", "futurepayments", "paypalattributes"],
this.onAuthorizationCallback, this.onUserCanceled);
},
buyNowBtn : function(data) {
// single payment
PayPalMobile.renderSinglePaymentUI(this.createPayment(data), this.onSuccesfulPayment, this.onUserCanceled);
return transcallPromise2.promise;
},
onPrepareRender: function() {
},
onUserCanceled: function(result) {
console.log(result);
transcallPromise2.reject(result);
}
}
}])
內部控制呼叫buyNowBtn methond
processPaypal.buyNowBtn($scope.MMParams).then(function(response){
console.log(response);
})
您確定該方法沒有返回承諾嗎?如果你執行'console.log(processPaypal.buyNowBtn($ scope.MMParams))',會發生什麼? 可能是承諾被拒絕或者沒有得到解決。 – ppham27
控制檯中是否有錯誤? –
@CharanCherry是的,有時我會得到:「TypeError:無法讀取未定義的屬性'then' –