javascript - Displaying created record Id in controller of Angularjs -


hi writing values database returns id of saved record. factory has following

return {     postnewr: $resource('/api/newrec', {}, {create: {method: 'post'}}) } 

in controller have

newr_factory.postnewr.create(recorddata, function(data){    alert(data.id); }); 

everything works fine. can see in browser developer tools in response returning id of newly created value i.e 22. in alert box undefined.' please let me know how can display value of id in alert box.

you have use $promise returned this:

newr_factory.postnewr.create(recorddata).$promise.then(function(data) {     alert(data.id); }); 

alternatively, , more "angular", like:

var new_record = new newr_factory.postnewr(recorddata); new_record.$save(function(data) {     alert(data.id); }); 

Comments

Popular posts from this blog

javascript - Trigger mouseenter when an animated element touches mouse -

json - Zend error Connection -

java - Using Spring @Transactional with a combination of readOnly and write, when does this entity get committed? -