Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primeng p-dropdown not firing change event

I'm using primeng 5.2.4 and I'm trying this:

<p-dropdown [options]="months" [(ngModel)]="selectedMonth"
   (change)="selectMonth()"></p-dropdown>

The selectMonth method gets called when the page first loads but not on subsequent selections from the drop down list. If I change this to a click event it works (but I get one event when the dropdown is clicked and another when the value is chosen).

Any ideas on what I might be doing wrong? I rolled back to 4.3.0 and see the same behavior.

Thanks!

like image 310
Michael Witt Avatar asked Apr 09 '18 20:04

Michael Witt


1 Answers

The primeng dropdown supports an event onChange that can be looked for any change in the drop down

app.component.html

<p-dropdown [options]="cities2" [(ngModel)]="selectedCity2" optionLabel="name" (onChange)="onChange($event)"></p-dropdown>

app.component.ts

onChange(event) {
    console.log('event :' + event);
    console.log(event.value);
}

This should help

like image 110
azharuddin irfani Avatar answered Sep 22 '22 13:09

azharuddin irfani