user3860557
user3860557

Reputation: 1

Not able to set Initial value in ngx-bootstrap typeahead

Hello I am using angular 16 "ngx-bootstrap": "^11.0.2",

I can not set default value means when user select the data from suggestive search and i have saved that value in DB and now when you load this control i want to pre fill selected value Below is the code in HTML

I am using [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([]);
      })
    );
  }

I have tried the official site but they do not have such example

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

Upvotes: -1

Views: 124

Answers (1)

nsquires
nsquires

Reputation: 1119

The ngmodel for the control is bound to a variable named search. You should be able to just do this.search = "apple"

Upvotes: 0

Related Questions