primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.21k stars 4.55k forks source link

Dropdown: p-dropdown in custom component ignors first ngModel value #14609

Open MayerMar opened 8 months ago

MayerMar commented 8 months ago

Describe the bug

hi, i've got a timing problem when wrapping your p-dropdown in a custom component.

Scenario:

Problem:

not sure, but could be that the effect() delays the internal behavior?

I upgraded from an older version of primeng prior to onPush and Signals, there this implementation worked without problems. The behavior can be "fixed" from within the wrapped component by delaying the first value transmitted via ngModel with setTimeout(), which feels odd.

Question is: is this a bug, an accepted problem or bad implementation on my side :-)

I made a stackblitz (link) example to show the problem:

Thanks & best regards!

Environment

Stackblitz, latest angular, latest primeng

Reproducer

https://stackblitz.com/edit/github-4z4rkv-shubex?file=src%2Fapp%2Fcustom-dropdown%2Fcustom-dropdown.component.ts

Angular version

17.1.0

PrimeNG version

17.3.3

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.18.0

Browser(s)

Chrome latest

Steps to reproduce the behavior

No response

Expected behavior

No response

philkrpp commented 7 months ago

yes same for me

gasparbarancelli commented 7 months ago

MultiSelect component has the same bug

KeithGillette commented 7 months ago

I believe we are experiencing the same timing issue with p-dropdown bound to [ngModel] with an initial value set through static initialization on a controller class property. In our case, the p-dropdown gets its value from the row in a p-table but I have created a much simpler StackBlitz reproduction that shows the timing issue with single p-dropdown components.

scurk1415 commented 7 months ago

We are having the same problem. When the dropdown is wrapped inside a custom form input component (with ControlValueAccessor). When the options are dynamically loaded (from BE call with async for example), the model gets auto updated to a null/empty (because the options are not yet available). Setting autoDisplayFirst to false helps a little, but doens't fix the issue if options/model value are changed after the first init of the component. Not sure why you are still using it in the code when its deprecated.

Version 17.3.3 still works ok.

domen-j8 commented 7 months ago

We're encountering the same issue with the p-dropdown component inside a custom input when data is loaded dynamically, leading to the model being reset to null. Latest working version is 17.3.3 with autoDisplayFirst set to false.

KeithGillette commented 7 months ago

I believe we are experiencing the same timing issue with p-dropdown bound to [ngModel] with an initial value set through static initialization on a controller class property. In our case, the p-dropdown gets its value from the row in a p-table but I have created a much simpler StackBlitz reproduction that shows the timing issue with single p-dropdown components.

I updated this reproduction to show the issue remains in today's release of 17.6.0.