【发布时间】:2017-02-08 14:33:53
【问题描述】:
我写了一个工厂方法:
myApp.factory('GetUserCurrentLocationService', ['$q', function ($q) {
var GetUserCurrentLocationService = {};
GetUserCurrentLocationService.getLocation = function () {
var def = $q.defer();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
def.resolve(position);
return def.promise;
});
}
}
return GetUserCurrentLocationService;
}
]);
在控制器中我写过:
GetUserCurrentLocationService.getLocation().then(function(response){
console.log(response);
},function(error){
console.log(error);
})
但是每当我运行它时,我都会收到错误 Cannot read property 'then' of undefined AngularJS
【问题讨论】:
标签: angularjs