我广泛使用$resource
。我希望能够在某些路线/资源上设置$ save的transformRequest
属性,但不能在其他路由/资源上设置。我怎样才能做到这一点?
在$resource(url, [paramDefaults], [actions], options);
定义中,您只能在自定义动作上设置transformRequest
,而不是$save
方法。
在$httpProvider.defaults.transformRequest
中,您无法确定您所在的路线/方法,因为您无法访问url / path,只能访问params数据。
我能想到的最好的:
$httpProvider.interceptors.push(function () {
return {
"request": function (config) {
if (config.method === "POST" && new RegExp("{myregexhere}").test(config.url)) {
// keep only the default
config.transformRequest.length = 1;
}
return config;
}
};
});