Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read response from angular resource $save() and also keeping original data
    text
    copied!<p>I am new to Angular. I am sure I am missing some basic stuff here.</p> <p>I have one object which I post to the server to create it. The Server returns the object Id, which I need to read and update the object I have in the client.</p> <p>The server will only return the object ID, however, at the client side, I have other data which I am not able to use when I perform a callback (I don't have access to the original data).</p> <p><a href="http://jsfiddle.net/QcDSk/3/" rel="nofollow noreferrer">The Following jsfiddle code has been added as a reference</a>:</p> <pre><code>//Get Angular Project module var app = angular.module("app", ['ngResource']); //create Project factory app.factory('Project', function ($resource) { return $resource('http://cmsanalyticsdev.pearson.com\\:8081/api/projects/:projectid', {projectid:'@id'}, {update: {method:'PUT', isArray:false}} ); }); //Controller for testing app.controller('ApplicationController', function ($scope, Project) { //Project object var project = new Project({"name":"New Project Test","thumbnail":"","statusid":"521d5b730f3c31e0c3b1e764","projecttypeid":"521f585c092a5b550202e536","teamid":"521f585a092a5b550202e521","authors":[{"firstname":"Dilip","lastname":"Kumar"}],"projectspecificmetadata":{"isbn13":"345345","guid":"asfas"},"modifiedby":"521f585a092a5b550202e525"} ); //Create new project project.$save(project, function (projectResponse) { project.projectId = projectResponse._id; alert(project.name); }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload