我怎樣才能返回數據使用承諾
有錯誤,successdata不是我的控制器中的函數,我不知道我在做什麼錯誤。我想念我的控制器中的東西嗎? 我通過調試應用程序響應OBSERV服務即將到來,但沒有將返回從中
var module = angular.module('app', []);
module.service("webservice", function($http,$q) {
return {
callservice:function(method,url,_data){
var deferred = $q.defer();
var promise = deferred.promise;
$http({
method: method,
url: App_Service_api+url,
data: _data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function (data, status, headers, config) {
if (data.success) {
deferred.resolve(data.message);
//return deferred.promise;
promise.successdata = function(fn) {
promise.then(fn);
return deferred.promise;
}
}
else {
deferred.reject("Plase Enter valid data.");
//return deferred.promise;
promise.errordata = function(fn) {
alert("error");
promise.then(null, fn);
return deferred.promise;
}
}
}).
error(function(data, status, headers, config){
deferred.reject("Plase Enter valid data.");
//return deferred.promise;
promise.errordata = function(fn) {
promise.then(null, fn);
return deferred.promise;
}
});
}
}
})
這裏是我的控制器代碼
webservice.callservice('POST',App_Service_login,inputs).successdata(function(data){
var alertPopup = $ionicPopup.alert({
title: 'Login Succesfull!',
template: 'Please check your credentials!'
});
})
.errordata(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!'
});
});
工作就像一個魅力thnks @manzapanza – Raj