我试图传递搜索字符串以从search.component.html的输入获取方法参数到search.service.ts 服务中: 我的参数是:
public params = new HttpParams().set('order', '0')
.set('search', '')
.set('batch', '1')
.set('batchSize', '40');
我的获取方法:
getObjects():: Observable<Array<objects>> {
return this.http.get<Array<objects>>(this.apiUrl + 'Get', { params: this.params }).pipe(
catchError(this.errorHandler)
);
在component.ts
ngOnInit() {
this.data.getObjects()
.subscribe((res: any[]) => {
this.objects = res;
}, error => {
console.log(error);
});