gpt4 book ai didi

AngularJS 资源 : how to update

转载 作者:行者123 更新时间:2023-12-02 07:38:59 28 4
gpt4 key购买 nike

我在服务器上使用 express-resource。在我的 AngularJS Controller 中:

    var User = $resource('/services/users/:userId', {userId:'@id'},
{ update: {method:'PUT'} }
);
$scope.save = function(user) {
user.$update(function(u) { console.log("User " + u)});
}

PUT 方法应该转到/services/users/2 但它实际上发送到/services/users所以我得到一个 404

顺便说一句,用户 ID 字段如果是 UserID(不是 userId 或 id),但我不明白我应该如何声明 URL。

最佳答案

好的,在深入挖掘之后我发现了

var User = $resource('/services/users/:id', {id:'@UserID'},
{ update: {method:'PUT'} }
);

关于AngularJS 资源 : how to update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13239644/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com