Skip to content
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

Initialization fails when asynchronous load is slow #36

Open
Crossbow78 opened this issue Nov 17, 2016 · 1 comment
Open

Initialization fails when asynchronous load is slow #36

Crossbow78 opened this issue Nov 17, 2016 · 1 comment
Labels

Comments

@Crossbow78
Copy link

Crossbow78 commented Nov 17, 2016

Description

In the scenario where the list is asynchronously loaded, and this loading takes 'too long', the dropdown will stay empty.

What seems to happen is this:
During pageload the dropdown gets initialized with the (still empty) html select list. When the dropdown items eventually arrive from the server, we'll populate the list on the Angular viewmodel, which in turn modifies the (hidden) html select list options. However, this change is not picked up by the Chosen dropdown.

Work-around (sort of)

A manual refresh after populating the Angular viewmodel works:
setTimeout(function() { $('#dropdown').trigger('chosen:updated'); }, 50);
...but this goes against the Angular model driven design. You would need to insert view-specific code into the controller which is ugly. On top of that, an artificial delay is needed in order to allow Angular apply the viewmodel changes to the DOM.

Reproduction

This can be easily reproduced on your own example page when using Google Chrome with network throttling enabled in the Developer Tools (eg. use the "Regular 2G" profile). Refresh the page, and all dropdowns will stay empty.

@adityasharat
Copy link
Owner

A $setTimeout is already being used in the $watchGroup callback here
Will have to dig deeper. Please go ahead if you want to pick this issue up. I'm currently unavailable to pick this, but will look into it soon.
@Crossbow78 thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants