I'm trying to figure out how to pass data to an API through Angular's $resource. I can GET or query any data from my test server currently, but I also want to see how to POST new data to the server. I am using this code that I've adapted from the AngularJS docs:
.factory("ResourceTest", function($resource) {
return $resource("http://ift.tt/1abyCs6", {id:'1'}, {
charge: {method:'POST', params:{charge:true}}
});
});
When I run ResourceTest.charge(); in my controller, it works fine, and I see a POST request in my server logs. But when I try to pass any parameters when I call the function (eg ResourceTest.charge({test:false});), the request will not go through, and I can't see any request in the logs. (same happens with .save(), in case anyone is wondering)
Anyone know if it's just a code error I'm making here? I'm pretty new to AngularJS. Thanks!
Aucun commentaire:
Enregistrer un commentaire