1

I am trying to use Select2 along with AngularJs. I am stuck at achieving two-way data binding using ng-model directive for select2. Also other directives like ng-change is also not working for me.

My guess is I am missing some initial setup that binds AngularJs with Select2.js. Can someone please point out what the minimal requirement for using select2 in AngularJs?

<div ng-controller="sampleController">
<select id="e1" ui-select2 ng-model="select2.text" ng-change ="change()" data-placeholder="Pick a number">
    <option value=""></option>
    <option ng-repeat="number in range" value="{{number.text}}">{{number.text}}</option>
</select>    

function sampleController($scope,$timeout){
    $scope.select2={text:"",id:""};
    $scope.range=[{text:"name1", value:"id1"},
    {text:"namea2", value:"id2"},
    {text:"name3", value:"id3"}];

    $timeout(function(){
        $("#e1").select2();},10
    )

    $scope.change = function()
    {//not able to reach this function on ng-change
        $scope.select2=$scope.range[1];
    }
}
Huangism
  • 16,278
  • 7
  • 48
  • 74
sweetcode
  • 159
  • 1
  • 12
  • I'd recommend checking out [this SO question](http://stackoverflow.com/questions/13047923/working-with-select-using-angulars-ng-options), but if you still have questions I can throw up an example – cjhin Aug 03 '14 at 18:32

0 Answers0