[英]Argument of type 'string' is not assignable to parameter of type 'AbstractControl'. Angular Reactive Forms
[英]Angular 4 - argument of type string[] is not assignable to type parameter of type 'string'
我有以下函數在TSlinting中顯示以下錯誤-有人可以建議我為什么收到此錯誤嗎?
Argument of type 'string[]' is not assignable to type parameter of type 'string'
cancelEvent(id): any {
let pages: Array<string> = [];
let requestParams = new HttpParams().set('pages[]', pages);
}
您不能在標頭中設置String [],它應為string類型,
set方法的定義是:
set(param: string, value: string): HttpParams;
所以value只能是一個string
。
let requestParams = new HttpParams().set('pages[]', pages); // it should be string
HttpParams()。set只能設置字符串值。但是您可以執行以下操作
let pages: Array<string> = [];
let requestParams = new HttpParams().set('pages[]', pages.join(','));
並使用split()將值返回數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.