Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app = "testApp">
  <head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  </head>
  <body ng-controller = "testcontroller">
    <div>
      <div ng-repeat = "opt in options">
          <select testdirective config-id="{{opt.a}}" display="{{opt.b}}" ng-init="opt.d = opt.a.toString()" ng-model="opt.d" style="width:100%"></select>
      </div>
    </div>
  </body>
</html>
 
var app = angular.module("testApp",[]);
app.controller("testcontroller", function($scope){
  $scope.options = [{"a":1,"b":2},{"a":2,"b":3},{"a":3,"b":4},{"a":4,"b":5}];
});
app.directive("testdirective",function(){
  return {
    link:function(scope, ele, attr) {
            ele.append('<option value="' + attr.value + '" selected="selected">' + attr.display + '</option>\n');
            ele.select2({
                theme: 'classic'
            });
            ele.val(attr.configId).trigger("select2:change")
    } 
  }
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers