-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropdown preselection might fail if options initialized later #651
Comments
I am still experiencing this issue with PrimeNG 4.2.0-rc.1. The object bound to the ngModel is set before the list is built. This results in the dropdown not showing the set value. The scenario is that a user selects a ticket from a datatable on another tab. When this ticket is selected the full ticket data is loaded from the Database and set to the object bound to the dropdowns ngModel. The active tab is then changed to the tab that contains the form with the dropdown, and the component that handles this form's ngOninit initializes the dropdown list. If the tab that contains the form is not set to lazy the dropdown loads fine, and the selected value is displayed, but if it is lazy, meaning the list gets initialized when the tab is selected after the ngModel value has been set, the value is not displayed. |
What is the solution? Why was this closed? |
I believe @cagataycivici stated that it is a change detection issue, and he was unable to reproduce. I have yet to look back into the project I was having this issue to verify. Try installing loadash into your project, and use either clone(), or cloneDeep() on the collection bound to the dropdown. |
I was able to hack it to work. |
I am still experiencing this issue, any info on how to solve it? |
@broweratcognitecdotcom |
@NishantJava switch to reactive forms |
I managed to fix this by initializing "selected ngModel" in execution-complete of subscribe for Observable of "list ngModel". This will delay initializing selected value until list is fully initialized.
|
this.currencyService.getAll().subscribe( |
The array reference needs to change as @amuratgencay did. this.currencyService.getCurrencies().subscribe(
currency => this.currencyList.map(i => { return { label: currency.code, value: currency } }),
error => MessageUtil.addError(this.messageService, 'Error in loading Currencies', error),
() => this.getSelectedCurrency()
); Here is an example |
Work for me. maybe help u. |
Maybe it's too late, but... |
@deusmar |
If options are initialized/changed later then the ngModel value, then preselection fails.
The text was updated successfully, but these errors were encountered: