I try to throw error modal window when the gps not enable. perhaps it's enabled then it will call servcie callback using $http.post method. But without gps function it's working and return promises fine. if use GPS method above the post method then i got some error like "Uncaught TypeError: Cannot read property 'then' of undefined" What's wrong with my code. Anyone can give me some idea..
服務工廠工廠使用GPS探測器函數中:
.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){
});
你可以添加一個'返回{'聲明serviceDataReq後':功能(reqUrl,reqData){',看看它是否起作用? – user3632710
未捕獲的SyntaxError:意外的令牌。在GPS功能 –