I am learning Angularjs and in my first application I am replacing the $http with $resource and getting error. The below was my earlier service and the current service:
angular.module('myApp')
.service('fetchData', function ($http, $rootScope, myService) {
// AngularJS will instantiate a singleton by calling "new" on this function
this.fetchNames=function() {
return $http.get(myService.getDomainUrl() + '/names.json');
}
});
Below is my new code with $resource
angular.module('myApp')
.service('fetchData', function ($resource, $rootScope, myService) {
// AngularJS will instantiate a singleton by calling "new" on this function
return $resource(myService.getDomainUrl() + '/names.json', {
query:{
method: 'GET',
cache: true
}
});
});
I am getting the below error: fetchData.fetchNames(...).success is not a function
When I try to handle the success callback when calling this function. Please tell me where I am going wrong and what is the correct way to handle the $resource in Angularjs.