Guest User

Untitled

a guest
Jul 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. combineLatest(this.heroes$, this.searchFormControl.valueChanges)
  2. .subscribe(([changedHeroData, searchTerm]) => {
  3. const heroesArray = Object.values(changedHeroData);
  4.  
  5. if (!searchTerm) {
  6. this.tableDataSource$.next(heroesArray);
  7. return;
  8. }
  9.  
  10. const filteredResults = heroesArray.filter(hero => {
  11. return Object.values(hero).reduce((prev, curr) => {
  12. return prev || curr.toString().toLowerCase().includes(searchTerm.toLowerCase());
  13. }, false);
  14. });
  15.  
  16. this.tableDataSource$.next(filteredResults);
  17. });
  18.  
  19. this.searchFormControl.setValue('');
Add Comment
Please, Sign In to add comment