当 gps 未启用时,我尝试抛出错误模式窗口。也许它已启用,然后它将使用 $http.post 方法调用 servcie 回调。但如果没有 gps 功能,它可以正常工作并返回承诺。如果在 post 方法之上使用 GPS 方法,那么我会收到一些错误,例如“Uncaught TypeError: Cannot read property 'then' of undefined”我的代码有什么问题。任何人都可以给我一些想法..
服务工厂:
.service('DataServiceFactory', function($http, $rootScope){ //dynamic $http JSON Data Passing service
return{
serviceDataReq : function(reqUrl, reqData){
cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){
if(enabled == 1){
return $http.post(reqUrl, reqData);
}else{
$rootScope.ErrorMsg = "Please Turn On your GPS location..";
$('#ErrorModal').modal('show');
}
}, function(error){
$rootScope.ErrorMsg = "GPS location Error : "+error;
$('#ErrorModal').modal('show');
})
}
}
})
在控制器中:
DataServiceFactory.serviceDataReq($rootScope.primaryLiveServiceApiUrl, angular.toJson($scope.LoginAuthReq)).then(function(response) {
}, function(error){
});