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

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -