select2 dropdown selected value doesn't get updated with the updated model

会有一股神秘感。 提交于 2019-12-11 02:33:02

问题


I use the latest select2 api (select2-3.4.5) and my html for select 2 looks like this.

     <select ui-select2 id="select2-test" ng-model="mymodel.myTitle">
        <option value="">Title</option>
        <option ng-repeat="title in nameList" value="{{title.key}}">{{title.name}}</option>
    </select>

I am performing a save call in my controller which saves the model and reloads the saved model back. This is done inside the following block.

     $timeout(function(){
        //if(!$scope.$$phase){
            $scope.$apply(function(){
                //update the model
                //update code
            })
        //};
    }, 50);

all my text fields gets loaded with the updated data and when I printout {{mymodel}}, I can see the updated model. I performed save and update call inside $scope.$apply with the intention of updating the dom elements.

after the update when I expand the dropdown (select2), I can see the correctly updated value selected inside the select options.

       <option XXXX selected="selected">MYSELECTED</option>

but select2-container which has

        <span class="select2-chosen">OLD</span> has the old value hence it is shown as the selected value.

Is this an issue with select 2 or am I missing anything?

来源:https://stackoverflow.com/questions/20137957/select2-dropdown-selected-value-doesnt-get-updated-with-the-updated-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!