javascript - AngularJS Ressource Contructor with Array -


i have ressource in angularjs, example

var posts = $resource('posts/:postid', { postid: '@_id' }) 

i can query list (array) of posts with

$scope.posts = posts.query(); 

i can create single post in constructor

$scope.post = new posts({     title: ...,     content: ... }); 

but cant is: create list of posts constructor, like:

$scope.posts = new posts([     {         title: ...,         content: ...     },     {         title: ...,         content: ...     },     {         title: ...,         content: ...     }, ]); 

with can $scope.posts.save() tries push whole list single post , leads error. isnt possible $scope.posts[...].save()/$scope.posts[...].remove() them individually?

i did obvious:

$scope.posts = []; [     {         title: ...,         content: ...     },     {         title: ...,         content: ...     },     {         title: ...,         content: ...     }, ].foreeach(function(post) {     $scope.posts.push(new posts(post)); }); 

it want.


Comments