で行われた後、私はサービス内のメソッドを呼び出していますし、サービスの作業が行われたとき、それは、データをコントローラに戻っ 、さらに仕事を続けるべきコントローラでの成功を返さないが、サービスが呼び出され、データが生成される方法は、コントローラが停止していると、コンソールにエラーが返された後:角度サービスは作業がサービス
エラー:
Error: d is undefined
sendOtp/<@http://xxxxxxx:8087/controller/resources/static/js/controller/mainController.js:71:14
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:14634:28
scheduleProcessQueue/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:14650:27
$RootScopeProvider/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:15916:16
$RootScopeProvider/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:15727:15
$RootScopeProvider/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:16024:13
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:10511:36
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:10683:7
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js:10624:1
CONTROLLER:
app.controller('signController', ['$scope','signUpService','$location','$rootScope', function($scope, signUpService, $location, $rootScope) {
$scope.OTP='';
function sendOtp(pNumber, countryId){
if(pNumber!==null){
$rootScope.pNumber = pNumber;
signUpService.sendPhoneOtp(pNumber,countryId)
.then(
function(d) {
/*$location.path('/otp', false);*/
$scope.OTP = d.response.result.otp;
console.error('OTP SENT SUCCESSFULLY'+$scope.OTP);
alert($scope.OTP);
},
function(errResponse){
console.error('Error while fetching OPT of NUMBER');
}
);
}else{
alert("Number can not be empty");
}
}
SERVICE INSIDE
METHOD:
function sendPhoneOtp(pNumber,countryId){
var deferred = $q.defer();
$http({
method: 'POST',
url: 'https://xxxxx.com/service/verify/phone',
data: {
phone: pNumber,
countryId: countryId
}
}).success(function(response){
deferred.resolve(response.data);
}).error(function(errResponse){
console.error('Error while OTP');
deferred.reject(errResponse);
});
return deferred.promise;
}
読み取り(http://taoofcode.net/promise-anti-patterns/)あなただけの' $ HTTP(...)を返すことができ、それ自体約束ですTEAD –
使用 'はconsole.log()'エラーメッセージを1として、 'response'をログに記録する' D 'は、レスポンスオブジェクトの構造が何であるかサービスで – Satpal
チェックundefined'あなたがそこに持っている 'あります。 'response.data'は存在しますか? – Sangharsh