Default $resource POST data

前端 未结 7 1339
天命终不由人
天命终不由人 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:24

    Might this solve your problem?

    services.factory("Product", function($resource) {
      return $resource("http://someUrl", {}, {
        get   : {method: "GET", params: {productId: "-1"}},
        update: {method : "POST", params:{}, data: {someDataKey: someDataValue}}
      });
    });
    services.factory("DefaultProduct", function(Product) {
      return function(){
         return new Product({
            data:"default";
         });
      };
    });
    services.controller("ProductCTRL",function($scope,DefaultProduct){
      $scope.product = new DefaultProduct();
    });
    

提交回复
热议问题