Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何进行RESTFUL PUT调用angulajrs_Json_Angularjs_Rest - Fatal编程技术网

Json 如何进行RESTFUL PUT调用angulajrs

Json 如何进行RESTFUL PUT调用angulajrs,json,angularjs,rest,Json,Angularjs,Rest,我对如何使用“PUT”进行RESTFUL API调用感到困惑。我基本上是想保存一个编辑过的概要文件,但我不知道如何为它调用API。这就是我目前所拥有的 var edit = angular.module('edit', ['ui.bootstrap','ngResource']) .factory('editable', function($resource) { return { // get JSON helper function getJSON

我对如何使用“PUT”进行RESTFUL API调用感到困惑。我基本上是想保存一个编辑过的概要文件,但我不知道如何为它调用API。这就是我目前所拥有的

var edit = angular.module('edit', ['ui.bootstrap','ngResource'])
.factory('editable', function($resource) {

    return {

        // get JSON helper function
        getJSON : function(apicall) {

            if(sessionStorage["EditUserId"] == undefined) {
               // get the user id
                var userid = sessionStorage["cerestiuserid"]; 
            }
            else {
                var userid = sessionStorage["EditUserId"];
            }


            // json we get from server
            var apicall = sessionStorage["cerestihome"];   

            // new api
            return $resource(apicall + "/api/profiles/", {Userid:userid}, {'PUT': {method: 'Put'}});  
        }
    };
});
这是控制器

//editable object
var object = editable.getJSON();
var edit = new object();

edit.UserName = "Hello World";
edit.$save();

使用restagular调用put服务

比如说

   admin.factory('AdminService', ['Restangular', 'AppConstants', 'AdminRestangular', 'WorkFlowRestangular', 'localStorageService',
        function(Restangular, AppConstants, AdminRestangular, WorkFlowRestangular, localStorageService) {

    var service = {}

        service.updateAgency = function(data) {

                return AdminRestangular.all(AppConstants.serviceUrls.agency).doPUT(data);
            };

    return service 
}]);

你有什么问题?看一看。页面底部有一个自定义PUT方法的示例。您检查了吗?,。希望这对你有用。是的,谢谢。简单的问题,但为什么你用工厂而不是模块?这两者有什么区别?