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

Template does not update after model change #71

Open
Jarzembowski opened this issue Jul 3, 2018 · 3 comments
Open

Template does not update after model change #71

Jarzembowski opened this issue Jul 3, 2018 · 3 comments

Comments

@Jarzembowski
Copy link

Jarzembowski commented Jul 3, 2018

I'm trying to set the items in the multiselect as select based on a model that I get from an http request.
Im not sure if this has something to do with the order I set the model and the options, but after the promise returns, I got both the options and the model, like this:

Model: [
{id: 1, nome: "Cafés"},
{id: 2, nome: "Bares"} ];

Options: [
{id: 1, nome: "Cafés"},
{id: 2, nome: "Bares"},
{id: 3, nome: "Restaurantes"}];

And the multiselect like this:

    <multiselect ng-model="Model" options="Options" id-prop="id" display-prop="nome"></multiselect>

The options are displayed correctly, like the options array, but the options on the model are not selected, and I think they should, because the multiselect element is displayed based on both the model and the options.
Basically the model is updated based on the template, but the opposite is not happening. When I set the model on the controller, I dont see this changes reflected in the template(display the items selected, for example).

image
Two of the items in this image should be selected, since they are in the model array.

@labrute
Copy link

labrute commented Jan 24, 2019

I have the same problem. But in my case Options are updated async.
I have discovered that the Model is reset when i change Options. So i do this :

copyModel = angular.copy(Models);
http.get().then((response) => {
  Options = response.data;
  // Here model is reset so i apply the copy
  Models = copyModel;
}

But the HTML component is not updated.
Instead of "2 selected" i have "Selection" until i click on drop button.

I try to call manually $digest but it didn't works

@abastien
Copy link

Same problem here

@michael-luk
Copy link

Same problem. If the options changed, you have to click the dropdown btn to apply the changes.

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

No branches or pull requests

4 participants