When using a WebService, I send JSON to the front-end and map it to display all its content in a table. My goal is to implement a search method that will filter the rows based on searched letters.
Component.ts
allCountries: AllCountry[];
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.allCountries.filter = filterValue.trim().toLowerCase();
} ^^^^^^^^^^^^
ERROR
Mapping
export class AllCountry {
name: string;
iso2: string;
iso3: string;
unicode: string;
dial: string;
currency: string;
capital: string;
continent: string;
}
HTML
<mat-label for="search">Search</mat-label>
<input matInput type="text" name="searchString" (keyup)="applyFilter($event)" placeholder="Type to search..." />
<table mat-table [dataSource]="allCountries">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>Country</th>
<td mat-cell *matCellDef="let allCountries">{{allCountries.name}}</td>
</ng-container>
<ng-container matColumnDef="iso2">
<th mat-header-cell *matHeaderCellDef>ISO 2</th>
<td mat-cell *matCellDef="let allCountries">{{allCountries.iso2}}</td>
</ng-container>
Error
Error TS2322: Type 'string' is not assignable to type '{ <S extends AllCountry>(callbackfn: (value: AllCountry, index: number, array: AllCountry[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: AllCountry, index: number, array: AllCountry[]) => unknown, thisArg?: any): AllCountry[]; }'.
I am encountering an error because "filter" is available for simple arrays but not for arrays of objects. Unfortunately, I cannot provide more code as it is unrelated to my current issue. Thank you for your assistance.