Last active
March 8, 2021 18:03
-
-
Save zalito12/c4d0a9968d943578137d1f48e7790ad3 to your computer and use it in GitHub Desktop.
RxJS Text filter input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input class="iconized" type="text" [ngModel]="search" (ngModelChange)="onChangeSarch($event)" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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