primeng p-dropdown not firing change event

Michael Witt picture Michael Witt · Apr 9, 2018 · Viewed 24.2k times · Source

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!

Answer

azharuddin irfani picture azharuddin irfani · Apr 10, 2018

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