In Angular, I am filtering according to the value I enter in the input, but when there is an empty value for the input, my data does not come back.
I get certain data based on the data I entered in the input, but not all data comes back when the input is empty.
applyFilter(value: string) {
const filterValue = value.trim().toLowerCase();
const filteredMap = new Map<string, any>();
this._todayShare.forEach((item, key) => {
if (key.toLowerCase().includes(filterValue) ||
JSON.stringify(item).toLowerCase().includes(filterValue)) {
filteredMap.set(key, item);
}
});
this._todayShare = filteredMap;
}
<input
[(ngModel)]="sharedsearchText"
(keyup)="applyFilter(sharedsearchText)"
style="width: 50%; margin-top: 1px; margin-bottom: 1px;"
matInput
placeholder="Ara..."
/>
New contributor
Serkan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.