ui-select2 icon indicating copy to clipboard operation
ui-select2 copied to clipboard

Selection does not change after option is added and model updated

Open justinmccombs opened this issue 10 years ago • 4 comments

http://plnkr.co/edit/vK0Obg0HWQnL1NPlFLlx?p=preview

When I add an object to the array of values bound to the select2 options, then update the ng-model bound to the select2 element, the new value is not shown as being selected.

justinmccombs avatar May 01 '14 19:05 justinmccombs

@justinmccombs similar issue with me. I'm loading data from a $resource into 2 select boxes inside a modal. Both of the selects are blank when the modal opens, but I check and see that the model value is correct.

I had to work around it with

    modal.opened.then ->
      setTimeout( ->
        $('[ui-select2]').select2() #refresh select2
      , 100)

(I'm using http://angular-ui.github.io/bootstrap/)

nunosilva800 avatar May 07 '14 23:05 nunosilva800

Actually that did not work. I had to rely on the $promise provided by $resource:

  $scope.myResource = Resource.query()
  $scope.myResource.$promise.then ->
    setTimeout( ->
      $('#select').select2('val', $scope.selected_id) #refresh select2
    , 500)

nunosilva800 avatar May 08 '14 00:05 nunosilva800

Thanks Onumis, your timeout idea worked for me (I used $timeout with no actual delay.) Standing by for some kind of fix. :)

buzzcola avatar Jun 04 '14 22:06 buzzcola

Thanks Onumis! I also used your method although I too opt for a fix.

eddiestat avatar Aug 28 '14 19:08 eddiestat