ui-select2
ui-select2 copied to clipboard
Selection does not change after option is added and model updated
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 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/)
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)
Thanks Onumis, your timeout idea worked for me (I used $timeout with no actual delay.) Standing by for some kind of fix. :)
Thanks Onumis! I also used your method although I too opt for a fix.