add The searchTerms RxJS subject

This commit is contained in:
Костя 2025-06-25 10:45:49 +03:00
parent ef2309f0f1
commit f6d361eb84
2 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<div id="search-component">
<label for="search-box">Hero Search</label>
<input #searchBox id="search-box" (input)="search(searchBox.value)" />
<ul class="search-result">
<li *ngFor="let hero of heroes$ | async" >
<a routerLink="/detail/{{hero.id}}">
@ -9,4 +9,4 @@
</a>
</li>
</ul>
</div>
</div>

View File

@ -37,4 +37,12 @@ export class HeroSearchComponent implements OnInit {
switchMap((term: string) => this.heroService.searchHeroes(term)),
);
}
private searchTerms = new Subject<string>();
// Push a search term into the observable stream.
search(term: string): void {
this.searchTerms.next(term);
}
}