`Can you bind ngModel values to make select options searchable?`

Is there a way to connect ngModel values with select-searchable options in Ionic so that default values from localStorage are displayed?

<ion-col col-6>
        <select-searchable okText="Select" cancelText="Cancel"
                           class="inputStyle"
                           item-content
                           [(ngModel)]="WarrentItem.deviceManufacturerId"
                           searchFailText="No results found"
                           [items]="allManufacturers"
                           itemValueField="id"
                           itemTextField="value"
                           [canSearch]="true"
                           (ionClear)="onClear($event)"
                           (onChange)="materialChanged2($event)">

        </select-searchable>

      </ion-col>

In this code snippet, I have a list of all manufacturers as options. However, I am looking for a solution to automatically set the default value stored in localStorage when opening this form. Thank you.

Answer №1

To implement this feature, follow these steps:

Embedding the HTML code

<ion-item>
    <ion-label>Port</ion-label>
    <select-searchable
        item-content
        [(ngModel)]="port"
        [items]="ports"
        itemValueField="id"
        itemTextField="name"
        [canSearch]="true"
        (onChange)="portChange($event)">
    </select-searchable>
</ion-item>

Adding TypeScript logic

ports = [
   { id: 1, name: 'Tokai' },
   { id: 2, name: 'Vladivostok' },
   { id: 3, name: 'Navlakhi' }
];
port = {
   id: 3,
   name: 'Navlakhi'
};

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

Conceal API request details on the network tab

I am currently working on an application built with Angular 10. I was wondering if there is a way to encrypt the request parameters or hide sensitive data. The issue is that anyone who can view the URL has access to both the Bearer token and the request pa ...

What is the best way to retrieve the values from the dynamically generated inputs in my .component.ts file through *ngFor?

Hey there, I am trying to extract the values from my dynamically generated inputs. Can someone guide me on how to do this so that I can manipulate them in my .ts file? Below is the current code snippet from my blabla.component.html: <form #f="ngFo ...

Issue with TypeScript: Error appears when importing express after running "npm i @types/express -D"

Struggling with adding the following line of code in an index.ts file: import express, { Application } from 'express'; Initially encountered an error with "from 'express'", so I ran npm i @types/express -D which fixed that is ...

Steps for ensuring a prop is required in TypeScript React based on a condition

interface IPerson { name: string; gender: string; vaccinated: 'yes'|'no'; vaccineName?: string } In this interface, the property vaccineName is optional while other properties are required. If the property vaccinated is yes ...

Error: Unable to access the 'TEXT_TYPE' property because it is undefined in the BarcodeScanner

I've been utilizing Ionic alongside BarcodeScanner, which can be located here. Here is my code snippet for encoding a piece of text: $scope.GenerateBarcode = function () { $cordovaBarcodeScanner.encode($cordovaBarcodeScanner.Encode.TEXT_TYPE, "1" ...

Tips for sending code confirmation in Amazon Cognito identity using nest.js

Having some issues with implementing AWS Cognito login in Nest.js? Check out this helpful guide on token validation: https://medium.com/weekly-webtips/token-validation-with-aws-cognito-and-nestjs-6f9e4088393c. I need to add a feature where users receive ...

Issue encountered with Next.js 13.4 and NextAuth: A Type Error stating that 'AuthOptions' is not compatible with type 'never'

Currently, I am in the process of developing a Next.js 13.4 project and attempting to configure NextAuth using the app/router. Unfortunately, I have encountered a type error that I am struggling to troubleshoot. Below is my route.ts file: import NextAuth, ...

Steps for generating a multer file using a link to an image

My current challenge involves downloading an image from a public URL, converting it into a multer file format, and then uploading it using an existing API. So far, I've experimented with axios using responseType: "blob" and responseType: "arraybuffer" ...

I am facing an issue with calling a controller from an HTTP GET request in ASP.Net Core 6 using a Single Page Application (SPA) endpoint

[UNSOLVED] - Seeking help from developers [Issue] As a newcomer to the industry, I apologize for my lack of experience in advance. I am currently facing a challenge with ASP.Net Core 6 and it seems like I am missing something simple, but I can't see ...

Using Typescript to establish a connection between ngModel and an object's property

Let's talk about how we can dynamically bind an input to an undefined property in an object. For example, we have an object named user: let user = {}; How can we bind an input to a property that doesn't exist yet? Like this: <input [(ngMode ...

Is it possible for a conditional type in TypeScript to be based on its own value?

Is it possible to use this type in TypeScript? type Person = { who: string; } type Person = Person.who === "me" ? Person & Me : Person; ...

Can Angular 4 experience race conditions?

Here is a snippet of my Angular 4 Service code: @Injectable() export class MyService { private myArray: string[] = []; constructor() { } private calculate(result): void { myArray.length = 0; // Perform calculations and add results to myAr ...

Include an additional query parameter called login_hint in microsoft-adal-angular6 directly from an Angular component

Utilizing the provided package https://www.npmjs.com/package/microsoft-adal-angular6 for logging into azure AD has been successful. In the app module, I have configured the extraQueryParamter as shown below: MsAdalAngular6Module.forRoot({` tenant: " ...

Is it possible to trigger the setState() function of a parent component when a child component is clicked?

Hey there, I'm a new developer diving into the world of Reactjs. I've been working on setting up a Todo app but struggling to configure it just right. My main challenge is getting a button to add items to the list when submitted. I think I'm ...

What is the best way to insert a triangle shape to the bottom of a div with an opacity level set at 0.2

https://i.stack.imgur.com/sqZpM.png I've been trying to create something similar, but my triangle keeps overlapping with the background in the next section. I've already spent 3 hours on it. Any help would be greatly appreciated. Check out my c ...

Experiencing Issues with Angular Service Worker - Outdated Build Persisting - Seeking Angular Resolution

A Revision to an Edit: The answer below clarifies the issue. Despite Angular SW working properly with hashing, there was a problem with the server re-hashing certain bundles, causing a mismatch between the client and server SW versions. Edit: Allow me t ...

Expanding the Mui Typescript breakpoints within a TypeScript environment

Encountering a typescript error when attempting to utilize custom names for breakpoint values: Type '{ mobile: number; tablet: number; desktop: number;}' is not compatible with type '{ xs: number; sm: number; md: number; lg: number; xl: numb ...

Encountering a problem while bringing in screens: 'The file screens/xxx cannot be located within the project or any of these folders.'

I am currently working on an iOS application using React Native technology. During the process of importing a specific screen, I encountered an error message. Can anyone provide guidance on how to resolve this issue? Error: Unable to resolve module scree ...

I require the ability to modify cellEditor parameters in real-time

How can a value be passed to cellEditorParams after the user double clicks on a grid row? The application triggers a service call on row click and the response needs to be sent to cellEditorParams. ...

Typescript: The ConstructorParameters type does not support generics

Incorporating TypeScript 3.7, I created an interface featuring a property designed to accept a constructor function: interface IConstruct<T> { type: new (...args:ConstructorParameters<T>) => T; } I initially assumed that IConstruct<Us ...