Ngresource Retrive Unique Id From Post Response After $save()
Solution 1:
You need to have a success handler to assign the new id to newQ
manually:
QuestionService.save(newQ, function(data) {
newQ.id = data.id;
});
But there is a better to achieve the same. Because your QuestionService
is a resource class object, you can instantiate your newQ
like this:
var newQ = new QuestionService({text: $scope.addTxt});
Then, call $save()
of newQ
:
newQ.$save();
Now newQ
should have the new id returned by the server.
- How Do I Resolve A 'mime Type Mismatch Error' Blocking An Ajax-requested Resource From My Google Apps Script?
- In My Service-factory I Lookup Up A Large Dataset - I Want To Persist It And Check For Its Existence To Avoid Calling It Again
- Extend Angular Controllers Using Controlleras Syntax & Prototypical Inheritance
Solution 2:
I have Asp.Net server with WebApi2 running, i use Ok(number) to return content, and it return for example '6' as result. once it return, the angular show an object containing promise and state, and prototypes and a deep repeated hierarchy, but no value, no '6'. So i went to see where the data goes, for seeing where the data is i define a transform, and i see awo the data, but it's not a json...
later i change it to following, and now i have a obj in my success function, which has sub property called 'returnValue' (as i defined), and this object hold my value.
transformResponse: function(data, header){
var obj={};
obj.returnValue=angular.fromJson(data);
return obj;
},
Post a Comment for "Ngresource Retrive Unique Id From Post Response After $save()"