将参数传递给$resource(使用 @)

Passing parameters to $resource (using @)

本文关键字:使用 resource 参数传递      更新时间:2023-09-26

在我的控制器中:

UserResource.find({ userId: userId }, function (records) {
                            $scope.user= records;
                        });

在我的资源中:

angular.module("main_k").
    factory("main_k.service.resource.Order", ["$resource", function ($resource) {
        return $resource("../rest/user/:action?:identification", {
            action: "@userId",
            identification: "identification51854"
        }, { find: { method: "GET"}
     });
    }]);

问题是 userId 被附加到 url 而不是被填充到操作中。 标识正确填写。为了传递 userId 值,我做错了什么?

有点奇怪。当你做GET请求时,你需要设置原始变量名:action而不是userId

如果你想插值路径。
UserResource.find({
    action: userId
}, function (records) {
    $scope.user = records;
});