Displaying a list of items in a dropdown menu that includes both the item's ID and name using angular

I am currently utilizing the angular2-multiselect-dropdown to connect with server values.

interface PayerDummyObjType{
id: string;
itemName: string;
}
PayerDummyObjType: PayerDummyObjType[];
PayerDummyObjTypeSelected: PayerDummyObjType[];  
dropdownSettings = {}; 

this.http.getPBMPayerDetails().subscribe((data: FilterDetails[]) => {
this.dropdownSettings = {
        singleSelection: false,
        text: "Select Payer",
        selectAllText: 'Select All',
        unSelectAllText: 'UnSelect All',
        enableSearchFilter: true,
        classes: "myclass custom-class-example",
        badgeShowLimit: 2,
        lazyLoading: true,
        labelKey: 'itemName',
        primaryKey: 'id',
        maxHeight: '200'
    };
this.PayerDummyObjType = []; 
data.forEach(x => {
this.PayerDummyObjType.push({ 
id:x.FILTER_VALUES, itemName:x.DISPLAY_NM                         
});
});

Below is my HTML code snippet:

 <angular2-multiselect [data]="PayerDummyObjType" [(ngModel)]="PayerDummyObjTypeSelected"
            [settings]="dropdownSettings" (onSelect)="onItemSelect($event)" (onDeSelect)="OnItemDeSelect($event)"
            (onSelectAll)="onSelectAll($event)" (onDeSelectAll)="onDeSelectAll($event)" (onOpen)="onOpen($event)"
            (onClose)="onClose($event)" (clickOutside)="onClose($event)">
 </angular2-multiselect>

I am facing an issue where both id and itemName are displayed in the dropdown. Attached below is a screenshot for reference. Any assistance on identifying the error would be much appreciated.

https://i.sstatic.net/aA4Ax.png

Answer №1

Resolved the issue by implementing Template Driven Forms.

<angular2-multiselect [data]="PayerDummyObjType" [(ngModel)]="PayerDummyObjTypeSelected" [settings]="dropdownSettings">
<c-item>
        <ng-template let-item="item">
          <label style="color: #333;min-width: 150px;font-weight: 500">{{item.itemName}}</label> 
        </ng-template>
</c-item>    

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

Tips for defining the types of nested arrays in useState

Looking for guidance on how to define types for nested arrays in a useState array This is my defined interface: interface ToyProps { car: string | null; doll: number | null; } interface SettingsProps { [key: string]: ToyProps[]; } Here is the stat ...

Guide to accessing Angular app on a mobile device within the same network

I'm facing an issue with my Angular App when trying to access it on mobile within the same network. I've attempted running ng serve --host <my IP> or ng serve --host 0.0.0.0 and it works well. However, the problem arises because the applica ...

Determine the conditional type based on the type of another variable

function updateFilterData( mode: 'PaymentType' | 'Origin' | 'Destination', value: string, ) { } I need to modify this function so that when mode is 'Origin' | 'Destination', the value should b ...

Can diff coverage be implemented for Angular 9 projects?

Currently, I am working on utilizing Angular 9 for my front end and .Net CORE for the backend. Successfully implementing differential coverage for the backend project involved the following steps: Within my azure-pipeline.yml: - task: DotNetCoreCLI@2 ...

Using Typescript to extract/calculate types with limitations without the need to explicitly extend or broaden them

I have a function called build that constructs a User object using the provided parameters. I want to define the function in such a way that it recognizes which parameters are being passed and incorporates them into the return value. Initially, I thought ...

Utilizing absolute path in Typescript: A comprehensive guide

I am currently working on a project written in Typescript running on NodeJS. Within the project, I have been using relative paths to import modules, but as the project grows, this approach is becoming messy. Therefore, I am looking to convert these relativ ...

What steps can I take to guarantee that the observer receives the latest value immediately upon subscribing?

In my Angular 2 and Typescript project, I am utilizing rxjs. The goal is to share a common web-resource (referred to as a "project" in the app) among multiple components. To achieve this, I implemented a service that provides an observable to be shared by ...

Expanding Mongoose Schema with Typescript: A Comprehensive Guide

Currently, I am in the process of creating 3 schemas (article, comment, user) and models that share some common fields. For your information, my current setup involves using mongoose and typescript. Mongoose v6.1.4 Node.js v16.13.1 TypeScript v4.4.3 Eac ...

Create a Typescript function that adheres to a specified type

Imagine a scenario where a specific type of function is declared within a type type Callback = (err: Error | null, result: any) type UselessFunction = (event: string, context: any, callback: Callback) => void The objective is to declare functions that ...

Nested self-referencing in Typescript involves a structure where

Please note that the code below has been simplified to highlight a specific issue. The explanation before the code may be lengthy, but it is necessary for clarity. Imagine I have a Foo class that represents a complex object. interface Config { bars:{ ...

What is the method for obtaining the union type of interface values (including string enums)?

How can I achieve the following ? Given : enum FooEnum1 { Foo = "foo", }; enum FooEnum2 { Foo = 1, }; interface FooInterface { foo1 : FooEnum1, foo2 : FooEnum2, foo3 : string, foo4 : number, }; I am interested in cre ...

Having difficulty implementing Angular 4 redirection for transitioning from old hash URLs to new non-hash URLs

In our single page application, we originally had a simple tab structure where each tab click led to a corresponding #url. Examples: , After transitioning to Angular 4, the urls no longer contain hash symbols. They now look like this: , I have added the ...

Exploring TypeScript integration with Google Adsense featuring a personalized user interface

After following a tutorial on implementing Google AdSense in my Angular App, I successfully integrated it. Here's what I did: In the index.html file: <!-- Global site tag (gtag.js) - Google Analytics --> <script> (function(i,s,o,g,r,a,m ...

Create a TypeScript function that can be called and has an extended prototype definition

I am seeking to create a callable function foo() (without using the new operator) that will also include a property foo.bar(). The JavaScript implementation would be as follows: function foo() { // ... } foo.prototype.bar = function bar() { // .. ...

Unforeseen results arise when using the ng-if directive on a DIV element within an Angular context

@angular/upgrade/static Attempting to upgrade an AngularJS controller to Angular context using UpgradeModule from '@angular/upgrade/static' Encountering issues when changing ng-show to ng-if on span or div elements, as the enclosed content does ...

`mat chip component in Angular Material is malfunctioning`

Whenever I input a string, it does not display properly within the designated textbox. HTML <mat-form-field class="favorite-fruits"> <mat-label>Favorite Fruits</mat-label> <mat-chip-list #chipList aria- ...

Preserve data even after refreshing the browser in Angular

Is there a reliable method to preserve my data after refreshing my browser? I've experimented with rxjs behavior subject, but it hasn't worked for me. I prefer not to use local/session storage due to security concerns and best practices, especia ...

The Angular reactive form is being submitted without completing the submission process

I've been working on an Angular 5 reactive form and everything seems to be functioning correctly. However, I've encountered a strange issue with a button used to close the form by hiding it from view. Whenever I click on this close button, the f ...

Error encountered while exporting TypeScript module

While I am working with Angular, TypeScript, and Gulp, my module system is CommonJS. However, I encountered an error when trying to import a module into my main.ts file: Error: Cannot find external module 'modules.ts'. Here is the snippet from ...

Utilizing the map function in Angular while disregarding any null values

I have an array of objects in my dataset. Here's a glimpse of how it is structured: [ { "id": 1, "name": "john", "address": { "number": 42, "street": "High Street"} }, { ...