AngularJS Restangular:如何从基本URL中删除默认请求参数

时间:2022-09-18 22:41:54
      EC2Restangular.setBaseUrl('localhost:9000/');
      EC2Restangular.setDefaultRequestParams({
        "Id": ID
      });

Is there any way to remove default query params from baseUrl in Restangular?

有没有办法从Restangular中的baseUrl中删除默认查询参数?

1 个解决方案

#1


0  

To remove the parameters you can just pass an empty object:

要删除参数,您只需传递一个空对象:

EC2Restangular.setDefaultRequestParams({});

If you want to remove the request parameters from a single request, you can add the empty object to the method call like so:

如果要从单个请求中删除请求参数,可以将空对象添加到方法调用中,如下所示:

Restangular.all("widget").getList({})

Update: To remove a specific paramter from the default parameter set is a little trickier.

更新:从默认参数集中删除特定参数有点棘手。

We can grab the parameter list from the Restangular object, and then use that to remove the parameter we don't need, and then use that new parameter object to pass to the new request:

我们可以从Restangular对象中获取参数列表,然后使用它来删除我们不需要的参数,然后使用该新参数对象传递给新请求:

var params = Restangular.all("projects").reqParams;

delete params['parameterNameYouWantToRemove'];

var projects = Restangular.all("projects").getList(params);

#1


0  

To remove the parameters you can just pass an empty object:

要删除参数,您只需传递一个空对象:

EC2Restangular.setDefaultRequestParams({});

If you want to remove the request parameters from a single request, you can add the empty object to the method call like so:

如果要从单个请求中删除请求参数,可以将空对象添加到方法调用中,如下所示:

Restangular.all("widget").getList({})

Update: To remove a specific paramter from the default parameter set is a little trickier.

更新:从默认参数集中删除特定参数有点棘手。

We can grab the parameter list from the Restangular object, and then use that to remove the parameter we don't need, and then use that new parameter object to pass to the new request:

我们可以从Restangular对象中获取参数列表,然后使用它来删除我们不需要的参数,然后使用该新参数对象传递给新请求:

var params = Restangular.all("projects").reqParams;

delete params['parameterNameYouWantToRemove'];

var projects = Restangular.all("projects").getList(params);