Having trouble assigning an initial value to ngx-bootstrap typeahead

Hello there, I am currently using Angular version 16 with ngx-bootstrap version 11.0.2.

I am facing an issue where I cannot set a default value for a control. When a user selects data from a suggestive search and it gets saved in the database, I want that selected value to be pre-filled when the control is loaded. Below is the HTML code snippet:

I have implemented [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 searched on the official site for examples, but unfortunately could not find one related to my issue. You can check out their website here: .

Answer №1

A variable named search is linked to the control's ngmodel. Simply assign this.search = "apple".

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loop through the ng-content elements and enclose each one within its own individual nested div

Although it is currently not supported, I am curious to know if anyone has discovered a clever solution to this problem. In my current setup, I have a parent component with the following template: <dxi-item location='after' class="osii-item- ...

CSS - Text and dropdown misalignment due to spacing issue

I'm looking to decrease the spacing between the text "Allow type of Compartment Option" and the dropdown box. Here is the code snippet being used: .cl-checkbox { padding-left: 20px; padding-bottom: 10px; padding-top: 20px; ...

By pairing delay(0) with refCount(), we can achieve optimal efficiency

The refCount operator is discussed in this article. It explains the necessity of adding delay(0) to prevent unsubscription of observable A: import { Observable } from "rxjs/Observable"; const source = Observable.defer(() => Observable. ...

Encountered an error while trying to run the command "lite-server" in Angular 2

I recently had a machine where I installed Zsh and OhMyZsh, but later on uninstalled them. However, now whenever I try to run "npm start" on the Angular 2 Quick Starter template, I keep encountering this error message: Error occurred when executing comma ...

Encountering a 500 Internal Server Error while using passport-jwt in a MEAN-Stack application

Using the passport.js JWT strategy to authenticate my MEAN-Stack app has been successful for unsecured routes, but I'm encountering issues with secured routes. Despite following the documentation, all secured routes consistently return an Internal Ser ...

Issues discovered with using Typescript in Visual Studio 2015

I'm having trouble figuring out the issue. Right now, the typescript file is not appearing correctly in Visual Studio 2015. Take a look at the image linked here: https://i.stack.imgur.com/oXXWD.png ...

Define the interface for a GraphQL resolver argument in code-first implementation

This specific GraphQL schema example from the Constructing Types page showcases how to define the Query type. // Creating the Query type var queryType = new graphql.GraphQLObjectType({ name: 'Query', fields: { user: { type: userType ...

Is it Control or ControlGroup in Angular 2 - How to tell the difference?

let aa = this._formBuilder.control(""); let bb = this._formBuilder.group({ aa: aa }; I am trying to achieve the following: if (typeof(aa) == "Control") { // perform a specific action } else if (typeof(aa) == "ControlGroup") { // perform anoth ...

The Authentication Key (FCM Token) was not provided in the request. For further details, please consult the "Authentication" section in the FCM documentation

When sending Firebase notifications from my NativeScript app using the Angular HTTP post module, I sometimes encounter an error stating that the request is missing an Authentication Key (FCM Token). The FCM documentation provides more information on this. ...

Ngrx effects are not compatible with earlier versions of TypeScript, causing issues with functionality

Seeking assistance with my Ionic 3 App utilizing ngrx/store and ngrx/effects. However, upon attempting to run the app, I consistently encounter the following error: TypeScript Error A computed property name in a type literal must directly refer to a bui ...

How can a new component be added as a child of an element without replacing or interfering with other

Whenever I dynamically generate components and attach them as children to an element upon creation, everything within that element gets deleted. Here's an example: public fn(event) { // Create component factory const factory = this.componentF ...

Display the values from form fields in Angular2 after dynamically adding them

I am struggling to output the values of each object in the choices array using console log. Despite being able to display the objects in the choices array, all the values appear empty. Every object is showing as timeZonePicker: "", startTimeInput: "", endT ...

Enhancing TypeScript with Generic Proxyify Functionality

I'm attempting to enclose a basic interface provided through a type generic in order to alter the return value of each function within the interface. For instance: interface IBaseInterface { test(a?: boolean, b?: number): Promise<boolean>; ...

What is causing ESLint to point out the issue with the @inheritdoc tag?

My code in ESLint is throwing an error about a missing JSDoc return declaration, even though I have included an @inheritdoc tag there: https://i.sstatic.net/QGxQh.png Here is the section from the interface I am inheriting from: export interface L2BlockSo ...

The projection of state in NGRX Store.select is not accurately reflected

Every time I run the following code: valueToDisplay$ =store.select('model','sub-model') The value stored in valueToDisplay$ always corresponds to 'model'. Despite trying various approaches to properly project the state, it s ...

Issue with RxDB: Collection not found upon reload

Exploring the integration of RxDB in my Angular project. I wanted to start with a simple example: export const LANG = { version: 0, title: "Language Key", type: "object", properties: { key: { type: "string", primary: true } }, requ ...

Listening to changes in a URL using JQuery

Is there a way to detect when the browser URL has been modified? I am facing the following situation: On my webpage, I have an iframe that changes its content and updates the browser's URL through JavaScript when a user interacts with it. However, no ...

Unable to find any routes that match child routes using the new Angular 2 RC1 router

ApplicationComponent import { Component } from '@angular/core'; import {Router, ROUTER_DIRECTIVES, Routes, ROUTER_PROVIDERS} from '@angular/router'; import {SchoolyearsComponent} from "./schoolyear/schoolyears.component"; @Component({ ...

core.js:15723 ERROR TypeError: Unable to access the 'OBJECT' property because it is undefined

Whenever I attempt to run this function, I encounter an issue. My goal is to retrieve the latitude and longitude of an address from Google's API. This error message pops up: core.js:15723 ERROR TypeError: Cannot read property 'geometry' of ...

Tips for generating search engine optimized URLs with category/subcategories/article slug in an Angular application

Currently, I am utilizing Angular 8 Version to develop a news application. My objective is to showcase the link in the following format: www.domain.com/category/category/title and www.domain.com/category. Can you guide me on how to accomplish this task? T ...