Setting initial values of Angular-UI Select2 multiple directive

前端 未结 2 814
一生所求
一生所求 2021-02-05 06:39

I have a select2 directive for a multiple select of countries with a custom query to grab the data:

// Directive


        
相关标签:
2条回答
  • 2021-02-05 06:57

    As requested by ProLoser here is a demo and github ticket.

    Demo: http://plnkr.co/edit/DgpGyegQxVm7zH1dZIJZ?p=preview

    GitHub Issue: https://github.com/angular-ui/angular-ui/issues/455

    Following ProLoser's advice I started using select2's initSelection function:

    initSelection : function (element, callback) {
      callback($(element).data('$ngModelController').$modelValue);
    },
    

    It does the trick but still feels like a workaround.

    0 讨论(0)
  • 2021-02-05 07:12

    Have you tried initialising your options as:

    <option selected value="0">Name</option>
    
    0 讨论(0)
提交回复
热议问题