Есть более чем одна вещь, которая не соответствует вашим запросам.
Во-первых, вы проходите Subject
и ожидаете Observable
.Вот почему вы получаете ошибку
TypeError: Невозможно прочитать свойство 'pipe' из неопределенного
Затем вы передаете Subject
как term
(я полагаюВы хотите отправить ключевое слово для поиска).
Вам не нужен Subject
в вашей ситуации.Вы можете сделать это так:
Шаблон:
<input type='text' class="form-control input-txt-start" placeholder="Search Domain Name" name="domainId" (keyup)='getSearchResults($event)'> <---- Send only $event here
Компонент:
getSearchResults(event) {
this.searchService.search(event.target.value).subscribe((res) => { // <--- Get target value of event
console.log(res);
this.results = res;
}, err => {
console.log(err);
this.error = err.message;
});
}
}
Сервис:
search(term) { // <--- Notice that the parameter name became term instead of terms
// You can use of() method of RxJS
// You need to import of with "import { of } from 'rxjs';"
// You can chain you operators in pipe() method with commas
return of(term).pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap(() => this.searchEntries(term) // <--- Notice that, this function has no parameter
);
}