Angular-网络
Angular
# Http
# Angular2中如何在发送delete请求时携带参数
前端angular:
/**
* 根据ids删除资源分组
*/
deleteResourceGroupByIds(ids: string[]) {
return this.http.request('DELETE', this.API + '/resourceGroup', {
body: ids
}).pipe(
retry(1),
catchError(this.handleError.bind(this))
);
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
后台springboot:
@DeleteMapping("/resourceGroup")
public void deleteResourceGroupByIds(@RequestBody String[] ids) {
resourceGroupService.deleteResourceGroupByIds(ids);
}
1
2
3
4
2
3
4
# angular中http请求的option、params使用
方式一:
let option = {};
const params = new HttpParams().append('key', String('val'));
params = params.append('status', String(status)); // 注意要从新赋值给params
option = {params};
1
2
3
4
2
3
4
方式二:
// 动态添加参数
const option = {};
const params = {};
if (v != null) {
params['k'] = v;
option['params'] = params;
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# http请求返回非json数据
返回类型:image/png
export class XxxService {
getRqCode() {
const url = '';
return this.http.post(url, {}, {
responseType: 'blob' // 类型
}).pipe(
retry(1),
catchError(this.handleError.bind(this))
);
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11