I have an angular application displaying a list of names. I have a search input to filter that list.
<input [ngModel]="searchStr" (ngModelChange)="modelChange($event)" type="text" id="employeeName">
The component has this logic for modelChange(), to capture the input string and filter my names by that string. This data initially comes from a service called in ngInit(). My issue is I am overwriting my names array with a filtered down array each time a key stroke is made in the input box. How can I write this logic to reset the array back to it's original contents when the input is blank?
modelChange(str: string): void {
debugger;
this.searchStr = str;
this.employeeList = this.employeeList.filter(emp => emp.name.includes(this.searchStr));
}
HTML template
<div *ngFor="let employee Of employeeList>
employee.name
</div>