我们如何将动态参数传递给ngbtypeahead

时间:2019-05-17 09:19:40

标签: angular bootstrap-4

我正在使用ngbtypeahead来获取Angular 6中的列表。我想基于在上一个文本字段中选择的某些条件来显示列表

例如。

<input type="text" class="form-control form-control-sm" 
    id="_state" name="_state" placeholder="State"
      [(ngModel)]="_stateLookup" required 
      [ngbTypeahead]="lookup.search('State', {})" 
      [inputFormatter]="lookup.formatter" [resultTemplate]="rt"
      (blur)="lookup.fillData(form, _stateLookup, '_stateCode', '_stateName')">


<input type="text" class="form-control form-control-sm" 
    id="_cityCode" name="_cityCode" placeholder="City"
      [(ngModel)]="_cityLookup" required 
      [ngbTypeahead]="lookup.search('City', {'_state': form._stateCode })" 
      [inputFormatter]="lookup.formatter" [resultTemplate]="rt"
      (blur)="lookup.fillData(form, _cityLookup, '_cityCode', '_cityName')">

我的lookup.service.ts文件具有以下功能

public search(type, searchParams:any) {
        let searchObservable = (text$: Observable<string>) =>
        text$.pipe(
          debounceTime(300),
          distinctUntilChanged(),
          switchMap(term =>
            this.getLookup(type, term, searchParams).pipe(
              catchError(() => {
                return of([]);
              }))
          ),
          map(data => this.handleData(data))
        )

        return searchObservable;

      }


    getLookup(lookupType, term, searchParams) {
        var lookupURL = "";
        searchParams.search = term;

        if(lookupType == 'State') { lookupURL = 'master/lookup/getstatelookup'; }
        if(lookupType == 'City') { lookupURL = 'master/lookup/getcitylookup'; }
        if(searchParams.search != undefined && searchParams.search.length >= this.strLen) 
        {
          console.log(searchParams);
          return this.core.post(lookupURL, searchParams);
        } else {
          return of([]);
        }
      }

我在这里传递_stateCode作为搜索中的参数。但是,它显示的是null而不是在“状态查找”中选择的内容。

如何在“州”文本框中选择具有适当州的城市? NgbTypeahead在调用时传递空值(它是初始值)

0 个答案:

没有答案