I have written a factory method as :
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;
}
]);
and in controller I have written:
GetUserCurrentLocationService.getLocation().then(function(response){
console.log(response);
},function(error){
console.log(error);
})
but whenever i am running this I am getting error Cannot read property 'then' of undefined AngularJS