bentorfs / angular-bootstrap-multiselect

Native angularJS custom form element
http://bentorfs.github.io/angular-bootstrap-multiselect/
MIT License
79 stars 111 forks source link

Template does not update after model change #71

Open Jarzembowski opened 6 years ago

Jarzembowski commented 6 years ago

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 commented 5 years ago

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 commented 4 years ago

Same problem here

michael-luk commented 4 years ago

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