文章内容
2023/5/4 16:44:46,作 者: 黄兵
Angular HttpClient HttpParams() 设置参数
下面是一些删除数据的示例:
public deleteFeatureInPlant(featureId: number, plantId: number): Observable<IPCrawlerModel> {
return this.http.delete<IPCrawlerModel>(`${this.requestSMSReceiveUrl}/product/features`, {
headers: new HttpHeaders().set('Authorization', this.auth.accessToken),
params: new HttpParams().set('featureId', String(featureId)).set('plantId', String(plantId)),
});
}
return this.http.delete<IPCrawlerModel>(`${this.requestSMSReceiveUrl}/product/features`, {
headers: new HttpHeaders().set('Authorization', this.auth.accessToken),
params: new HttpParams().set('featureId', String(featureId)).set('plantId', String(plantId)),
});
}
这里使用了 HttpHeaders()
设置 http
header
,来传递认证信息。同时使用 HttpParams() 传递需要删除的参数,这里需要注意两个问题:
1、HttpParams()
的多参数,有以下几种写法:
let params = new HttpParams().set('aaa', 'A'); // now it has aaa params = params.set('bbb', 'B'); // now it has both
或者是使用链式写法:
const params = new HttpParams() .set('one', '1') .set('two', '2');
以上就是本文全部内容。
参考资料:
1、Angular 4.3 - HttpClient set params
其它相关推荐:
4、Angular - “has no exported member 'Observable'”
黄兵个人博客原创。
redis.exceptions.ConnectionError: Error 111 connecting to redis-server:6379. Connection refused.
Python 对列表进行排序
Python 对列表进行排序
评论列表