繁体   English   中英

角4-string []类型的参数不能分配给'string'类型的参数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM