Reputation: 594
I have my data in json at controller, now i want to send that data to an post api call in service. service - Article
At my controller :
var annotationScripts = {startOffset : range.startOffset , endOffset : range.endOffset};
Article.post({id: $routeParams.articleId},{data : annotationScripts}
);
At my service :
factory('Article', function($resource) {
return $resource('article/:id', {}, {
query: { method: 'GET', isArray: false },
post : { method: 'POST', params:{id : '@id'} , data : {@data}, headers: {'Content-Type': 'application/x-www-form-urlencoded'}}
})
});
Upvotes: 0
Views: 1586
Reputation: 981
Why dont you use $resource out of the box features?
Here's a post example, with a simplified version of what you already have:
Resource service
factory('Article', function($resource) {
var Article = $resource('article/:id', {id: "@id"});
return Article;
});
Controller
var article = new Article();
article.startOffset = range.startOffset;
article.endOffset = range.endOffset;
article.$save();
Upvotes: 1