Search code examples
angulartypescriptangular2-template

Angular Argument of type 'array' is not assignable to parameter of type 'string'


I have json:

  public example=[{
       array:[item1, item2,]
    },
    {
       array:[item1, item2,]
    }]

file html:

<div *ngFor="let item of example">
      <div *ngIf="check(item.array)"> ...</div>
</div>

but call function check inside ngOnInit(), it error

 check(...request: string[]){
        return this._RolesService.checkRoles(request);
    }

ngOnInit(): void {
       let req:string[] = ['string1'];
        if(this.check(req)){}
}

gender html is ok, so When i call function check() in ngOnInit, it had error: Argument of type 'string[]' is not assignable to parameter of type 'string'.


Solution

  • You should change your code into:

    let req:string[] = ['string1'];
    if(this.check(...req)){}
    

    Or

    let req = 'string1';
    if(this.check(req)){}