你好,我正在使用 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.
控件的
ngmodel
绑定到名为 search
的变量。你应该能够做到 this.search = "apple"