In the following search method, I just set the BehaviourSubject
value in the service. So, I am not sure if I can perform this without using subscribe()
or toPromise()
after .pipe()
block in the following method. But if not, which one should I use? And, assuming that there is no validation for the search input, should I get the response or subscribe to the result of setting this value?
search() {
fromEvent(this.searchInput.nativeElement, 'keyup').pipe(
// get value
map((event: any) => {
return event.target.value;
}),
debounceTime(1000),
distinctUntilChanged()
)
// subscribe ?
.subscribe(x => {
this.searchService.setSubject(x);
});
// toPromise ?
.toPromise().then(x => {
this.searchService.setSubject(x);
});
}