angularjsangularjs-select2

select2 inside ng-repeat not working


I am trying to use select2 inside ng-repeat but its not working . Here is my code.

HTML

<div ng-controller="mycontroller" ng-app="app">
  <div ng-repeat="x in y">
    <input type="hidden" id="change{$$index$}"/>
  </div>
</div>

ANGULARJS

var myapp = angular.module('app', ['ui.bootstrap']);
myapp.controller('mycontroller',function($scope){
$scope.y=[1,2]
var change1 = $('#change1');
$(change1).select2({
      data:[{'id':1,'text':'Manager'},{'id':2,'text':'Employee'}],
      multiple: false,
      width: "100%",
      placeholder:"None Selected",
      closeOnSelect:true
  });
})

Please help.Thanks


Solution

  • The mistake was actually with the concatenation. But i didn't realised it from comment, but now i got it.Here is the change in code.

    var change1 = $('#change1'); //in question
    var change1 = $('#change'+1+''); //edited change
    

    Thanks.