// Set up the $resource
$scope.Users = $resource("http://localhost/users/:id");
// Retrieve the user who has id=1
$scope.user = $scope.Users.get({ id : 1 }); // returns existing user
// Results
{"created_at":"2013-03-03T06:32:30Z","id":1,"name":"testing","updated_at":"2013-03-03T06:32:30Z"}
// Change this user's name
$scope.user.name = "New name";
// Attempt to save the change 
$scope.user.$save();
// Results calls POST /users and not PUT /users/1
{"created_at":"2013-03-03T23:25:03Z","id":2,"name":"New name","updated_at":"2013-03-03T23:25:03Z"}
我希望这会导致带有更改属性的PUT到/ users/1.但它改为POST/users,它会创建一个新用户(新ID和新名称).
有什么我做错了吗?
AngularJS v1.0.5
你只需要告诉$资源,他如何将路由参数":id"与JSON对象绑定:
$scope.Users = $resource("http://localhost/users/:id",{id:'@id'});
这应该工作,问候
| 归档时间: | 
 | 
| 查看次数: | 7820 次 | 
| 最近记录: |