How to read response from angular resource $save() and also keeping original data

99封情书 提交于 2019-12-05 09:18:05

I think you want something like this:

//Controller for testing
app.controller('ApplicationController', function ($scope, Project) {

        //Project object
        var projectData = {"name":"New Project Test","thumbnail":"","statusid":"521d5b730f3c31e0c3b1e764","projecttypeid":"521f585c092a5b550202e536","teamid":"521f585a092a5b550202e521","authors":[{"firstname":"Dilip","lastname":"Kumar"}],"projectspecificmetadata":{"isbn13":"345345","guid":"asfas"},"modifiedby":"521f585a092a5b550202e525"};
        var project = new Project(projectData);

        //Create new project
        project.$save(project, function (projectResponse) {
                                projectData.projectId = projectResponse.id;
                                console.log("ProjectData: %j", projectData);
                            });

    });
joy

Following is similar approach for $update.

 //keep original data to pass into callback
 var originalProjectObject = angular.copy(project);
 //Call server to update the project data
 project.$update({ projectid: project._id }, function (projectResponse) 
 {
   originalProjectObject._id = projectResponse._id;
   //update scope
   scope.project = originalProjectObject;                        
 },originalProjectObject);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!