无法在 ngx-bootstrap typeahead 中设置初始值

问题描述 投票:0回答:1

你好,我正在使用 Angular 16 “ngx-bootstrap”:“^11.0.2”,

我无法设置默认值意味着当用户从建议性搜索中选择数据并且我已将该值保存在数据库中,现在当您加载此控件时我想预填充所选值 以下是 HTML 代码

我正在使用 [typeaheadAsync]="true"


 <input [(ngModel)]="search" 
typeaheadOptionField="AgencySearchText" 
[typeahead]="suggestions$"
[typeaheadAsync]="true" 
[typeaheadMinLength]="4" 
[optionsListTemplate]="customListTemplate"
class="form-control" 
[name]="label" 
(keydown)="onTypeaheadKeyPress($event)"
(typeaheadOnSelect)="typeaheadOnSelect($event)" 
[required]="required" 
[disabled]="disabled">
ngOnInit(): void {
    this.suggestions$ = new Observable((observer: Observer<string | undefined>) => {
      observer.next(this.search);
    }).pipe(
      switchMap((query: string) => {
        if (query && query.length > 3) {
          return this.srvAgency.GetSearchAgencyLookup(query)
        }
        return of([]);
      })
    );
  }

我已经尝试过官方网站,但他们没有这样的例子

https://valor-software.com/ngx-bootstrap/#/components/typeahead?tab=overview.

angular typescript bootstrap-5 ngx-bootstrap bootstrap-typeahead
1个回答
0
投票

控件的

ngmodel
绑定到名为
search
的变量。你应该能够做到
this.search = "apple"

© www.soinside.com 2019 - 2024. All rights reserved.