Default $resource POST data

前端 未结 7 1234
天命终不由人
天命终不由人 2021-02-07 11:51

That might be strange but I need to specify some default POST data for my $resource using the factory method of the module.

Does anyone have an idea of how to do that in

7条回答
  •  甜味超标
    2021-02-07 12:25

    You can just merge your params with the default. Everything not available in params will be provided by the default object. Everything available will be overwritten by myParams

    services.factory("Product", function($resource) {
        return $resource("http://someUrl", {}, {
            get   : {method: "GET", params: {productId: "-1"}},
            update: {method : "POST", params:angular.extend(myDefault, myParams);}
        });
    });
    

    where myParams would be your list of variables and myDefault your default values as a json object.

提交回复
热议问题