Angular $资源POST

时间:2012-09-26 05:21:23

标签: angularjs

我得到了以下使用GET的示例..但是'doSave'不能用于POST。 我忽略了一些吗?


    $scope.obj1 = $resource('http://localhost:port/srv/:id',
            {port: '\:8080', id:'2', callback: 'JSON_CALLBACK'},
            {get:{method:'JSONP'}, save:{'POST'});


    $scope.doSearch = function () {
    $scope.Result = $scope.obj1.get({id:$scope.term});
    }

    $scope.doSave = function () {
    $scope.Result.save();
    }

1 个答案:

答案 0 :(得分:1)

除了查询/获取方法之外,其余的都被称为前缀为$($ resource。$ save(),$ resource。$ remove()等)

所以在doSave中你需要

$scope.Result.$save();

official docs

中的更多详细信息