Skip to content

Instantly share code, notes, and snippets.

@zalito12
Last active March 8, 2021 18:03
Show Gist options
  • Save zalito12/c4d0a9968d943578137d1f48e7790ad3 to your computer and use it in GitHub Desktop.
Save zalito12/c4d0a9968d943578137d1f48e7790ad3 to your computer and use it in GitHub Desktop.
RxJS Text filter input
<input class="iconized" type="text" [ngModel]="search" (ngModelChange)="onChangeSarch($event)" />
private searchChanged$ = new Subject<string>();
public search: string = null;
ngOnInit(): void {
this.searchChanged$
.pipe(takeUntil(this.destroy$), debounceTime(300), distinctUntilChanged())
.subscribe((searchFilter) => this.onSearchFilter(searchFilter));
}
onChangeSarch(textFilter: string) {
this.searchChanged$.next(textFilter);
}
onSearchFilter(textFilter: string) {
this.currentFilter = this.FILTER.SEARCH;
this.search = textFilter;
if (!textFilter) {
this.onFilter(this.FILTER.ALL);
return;
}
this.filtedSkills$.next(
this.skills
.filter((skill) => skill.name.toLocaleUpperCase().includes(textFilter.toLocaleUpperCase()))
.sort(this.sortBy(this.currentOrder))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment