Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
Angular2 + PrimeNG - Dropdown selected value not working properly if Editable is set

I have an Angular2 application with PrimeNG suite installed.

I'm trying to implement a form with a primeNG dropdown component.

The problem happens when I run the application and I select an element from the listbox.

Instead of shows the value, it shows [object Object]

the problem

enter image description here

html component

 <p-dropdown [options]="listCustomers_itm" placeholder="Selezionare" formControlName="Customer_itm" [(ngModel)]="Customer_itm" filter="filter" editable="editable"> </p-dropdown>

declarations

 /*primeng listBox */
  Customer_itm: SelectItem;
  listCustomers_itm: SelectItem[];

ts code to fill the options:

this.mdService.Get_Customer(false).subscribe(
      data => {
        this.listCustomers = data;

        this.listCustomers_itm = [];
        for (let c of this.listCustomers) {
          this.listCustomers_itm.push({ label: (c.code + ' - ' + c.businessName), value: { id: c.idCustomer, name: c.businessName, code: c.code } });
        }

      }
    );

If instad of use custom label and value, is use flat values like:

this.listCustomers_itm.push({ label: c.code, value:c.businessName });

All works properly...

I tried also to implement onChange function:

  onCustomerSelect(e)
  {   
    console.log(e);        
  }

The ouput in the console when I select an item is:

Object { id: 5, name: "Luigino Gatto", code: "5" }

I finally discovered that the code works properly if I remove editable="editable" attribute, but I need to set it editable...

Thanks to support

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Instead of pushing individual values in the value you can put the entire object in it.

this.mdService.Get_Customer(false).subscribe(
  data => {
    this.listCustomers = data;

    this.listCustomers_itm = [];
    for (let c of this.listCustomers) {
      this.listCustomers_itm.push({ label: (c.code + ' - ' + c.businessName), value: c });
    }

  }
);
over 4 years ago · Santiago Trujillo Denunciar

0

from your template it looks like to trying to work with model driven (formcontrolName) and template driven (ngModel) approach.

which does not make sense.

<p-dropdown [options]="listCustomers_itm" placeholder="Selezionare" **formControlName**="Customer_itm" **[(ngModel)]**="Customer_itm" filter="filter" editable="editable"> </p-dropdown>

Please select the appropriate why and use it correctly.

over 4 years ago · Santiago Trujillo Denunciar

0

I was having the same issue. From what I can tell, when provided with an object as a value, the p-dropdown component will call value.toString().

In order to fix this, I added the following method to the object I wanted in the value field.

toString() : string{
  return this.name.toString();
}

Just to clarify as to why I'm using name.toString() - Prime likes to work with Typescripts primitive string rather than the wrapper object String.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda