I am trying to filter my array in my angular 4 component. The array has a property which itself is an array too:
export const data = [
{
"number": "1",
"lines": [
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
]
}
,
{
"number": "2",
"lines": [
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
]
}
,
{
"number": "3",
"lines": [
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
"aaaaabbbb bbbbb ccccc ddddd",
]
}
]
This is part of the component.html:
<input (keyup)="search($event.target.value)" />
<tr *ngFor="let item of filteredData">
<td>{{item.number}}</td>
<td>{{item.lines}}</td>
</tr>
This is part of the filter/search ts-code:
export class AppComponent {
filteredData = data;
search(val: any) {
let ind = false;
console.log(val);
if (!val) this.filteredData = this.data;
//this statement does not work:
this.filteredData = this.data.filter(item=> item.lines.indexOf(val) >=0)
}
}
How can I filter my data? Ignore the angularcode it is more about the filter statement.