Angular ngbTypeahead-传递参数

Angular ngbTypeahead-传递参数,angular,ng-bootstrap,typeahead,Angular,Ng Bootstrap,Typeahead,我正在使用ngbTypeahead进行提前输入搜索功能,但我想知道是否可以将参数传递给搜索功能 <input id="typeahead-basic" type="text" class="form-control" [(ngModel)]="model" [ngbTypeahead]="search(param1, param2)"/> 棱角的 search = (text$: Observable<string>) => text$.pipe( deb

我正在使用ngbTypeahead进行提前输入搜索功能,但我想知道是否可以将参数传递给搜索功能

<input id="typeahead-basic" type="text" class="form-control" [(ngModel)]="model" [ngbTypeahead]="search(param1, param2)"/>

棱角的

search = (text$: Observable<string>) =>
text$.pipe(
  debounceTime(300),
  distinctUntilChanged(),
  tap(() => (this.searching = true)),
  switchMap(term =>
    this.underwritingServiceWrapper.search(term).pipe(
      tap(() => (this.searchFailed = false)),
      catchError(() => {
        this.searchFailed = true;
        return of([]);
      })
    )
  ),
  tap(() => (this.searching = false))
)
search=(text$:Observable)=>
文本$.pipe(
去BounceTime(300),
distinctUntilChanged(),
轻触(()=>(this.search=true)),
开关映射(术语=>
此.underwritingServiceWrapper.search(term).pipe(
点击(()=>(this.searchFailed=false)),
捕获错误(()=>{
this.searchFailed=true;
归还([]);
})
)
),
轻触(()=>(this.search=false))
)
我已经检查过了,但似乎不起作用。


有人能帮我举个例子吗?

ngbTypeahead输入应该是一个函数,它以字符串的可观察值作为参数,并返回数组或结果的可观察值。也就是说,它必须是
(文本:Observable)=>Observable
(如api文档所示)类型

如果
search
是一个接受两个参数并返回这样一个函数的方法,那么您的代码就可以了:

search(param1: SomeType, param2: SomeOtherType): (text: Observable<string>) => Observable<any[]> {
  return (text$: Observable<string>) => text$.pipe(
    ...
  );
} 
search = (text$: Observable<string>) =>
  text$.pipe(
    // use this.param1 and this.param2 here 
  );

当我使用Observable Code时,我成功地做到了这一点:search(param1:SomeType,param2:SomeOtherType):(text:Observable)=>Observable{….}但是Observable抛出了这个错误。这意味着search()返回的是Observable,而不是Observable。你必须修正那个方法。