Tuesday 15 February 2011

javascript - Getting ids for newly created resource in Angular factory from server -


I have a node. I am creating an angular application supported by the JS / Mongodb application.

ID is generated by Mongodb for each resource when a resource is created.

I POST After the new object on a server from a factory to the server, the response code with the location header set to the server of the new resource How do I handle the response and then the correct id ? I can update the record with

  angular.module ('myApp.Todoservices', ['ngResource']). Factory ('Todo', function ($ resource) {return $ resource ('http: // localhost \\: 3000 / todos /: id', {id: '@_ id'}, {getAll: {method: ' Update: {method: 'POST'}, delete: {method: 'DELETE'}})}};   

As told before, it is not supported by $ resource , I know However, here's my work.

  var tmpPart = New MyResource ({name: $ scope.item.name}); TmpPart. $ (Function (_tmpPart, feedback header) { $ Resource (feedback header ( "Space").) (Function (tempResourceObject) {$ scope.myResourceObjects.push (New MyResource (tempResourceObject)}}}}   

Where New MyResource (tempResourceObject) is a new example of your resource object, you can do whatever you like with it.

No comments:

Post a Comment