Created
July 18, 2018 03:45
-
-
Save ZackDeRose/fde362c0f13559bae9b5061fa440c3b1 to your computer and use it in GitHub Desktop.
Initializing Subjects for Searching from "Angular CDK Tables" article
This file contains hidden or 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
combineLatest(this.heroes$, this.searchFormControl.valueChanges) | |
.subscribe(([changedHeroData, searchTerm]) => { | |
const heroesArray = Object.values(changedHeroData); | |
if (!searchTerm) { | |
this.tableDataSource$.next(heroesArray); | |
return; | |
} | |
const filteredResults = heroesArray.filter(hero => { | |
return Object.values(hero).reduce((prev, curr) => { | |
return prev || curr.toString().toLowerCase().includes(searchTerm.toLowerCase()); | |
}, false); | |
}); | |
this.tableDataSource$.next(filteredResults); | |
}); | |
this.searchFormControl.setValue(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment