When implementing the search method below, I simply assign the value of BehaviourSubject
in the service. However, I am unsure whether it is possible to execute this operation without using either subscribe()
or toPromise()
after the .pipe()
block in the method provided. If not, which approach should be followed? Additionally, assuming no validation for the search input, should I fetch the response or subscribe to the result after setting the 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);
});
}