I would like to interact with a REST API using $resource
but when calling the save method I get has no method '$save'
error. My code is inspired by the answer found on AngularJS $resource RESTful example
myapp.factory('Monitoring', function($resource) {
return $resource('http://localhost:8080/wepapp/network/v1/cronjobs/:id', { id: '@id' } );
});
Q1: What is the purpose of @
in { id: '@id' }
? I found it in most of the examples.
myapp.factory('MonitoringCRUDControllerService', ['Monitoring', function(Monitoring) {
return {
create: function(id, command, schedule) {
console.log("create");
console.log(command);
console.log(schedule);
Monitoring.id = id;
Monitoring.command = command;
Monitoring.schedule = schedule;
console.log(Monitoring);
Monitoring.$save();
}
}
}]);
The Monitoring
object is correctly injected:
function Resource(value){
copy(value || {}, this);
}
Calling the $save
failed with the error has no method '$save'
.
Q2: What the purpose of $
before save?
Q3: What am I missing to make the save method work?