Angular 9 PrimeNG p-dropdown selected value

862 views Asked by At

I have a list of objects that can be expanded and edited, with a couple of drop-downs that are populated once you expand. Each row is an object of the type Gama: { IdMaterial: 2,IdProveedor: 2, ..other props } on onRowExpand, i populate a dropdown inside the expanded form, like so:

onRowExpand(event){
this.gamaService.getMaterialesPorProveedor(event.data.IdProveedor).then(data => this.materialesPP =  data);
this.selectedMaterial = event.data.IdTipoMaterial;}

So this.selectedMaterial = gama.IdTipoMaterial from the expanded object (not even sure that's the way)
materialesPP is an array of Material objects coming from an API call (from a client, untouchable):

{ IdTipoMaterial:number; NombreMaterial:string; IdProveedor:number;}

this is my dropdown:

<p-dropdown dataKey="IdTipoMaterial"  [(ngModel)]="selectedMaterial" [options]="materialesPP" optionValue="IdTipoMaterial" optionLabel="NombreMaterial"></p-dropdown>        

I also tried without the selectedMaterial at all:

<ng-template pTemplate="rowexpansion" let-gama let-columns="columns" let-i="rowIndex">
    <tr [pEditableRow]="gama">
        <td [attr.colspan]="columns.length + 1">
           <p-dropdown dataKey="IdTipoMaterial"  [(ngModel)]="gama.IdTipoMaterial"  [options]="materialesPP" optionValue="IdTipoMaterial" optionLabel="NombreMaterial"></p-dropdown>                    

The dropdown populates just fine, the problem is, it doesn't get selected with the gama.IdTipoMaterial

I'm new to both angular and primefaces, so I'm pretty sure I'm messing up.

Kinda desperate here, thank you very much!

0

There are 0 answers