title: Not able to get data using query function in select2 and angularjs
body: <p>I am  implementing jQuery select2 in angularjs.</p>
  
  <p>Html:</p>
  
  <pre><code>&lt;input type="hidden" ng-model="multiselect" style="width:300px;" dev &gt;
  
  id  {{multiselect.id}}    // want  to print  selected items id
  
  text  {{multiselect.text}}   //want  to print  selected items   text
  </code></pre>
  
  <p>Directive code </p>
  
  <pre><code>app.directive('dev',[function(AutoCompleteService) {
  return {
      restrict: 'A',
      link: function(scope, elem, attr, ctrl) {
  
            $(elem).select2(
                  {
                      minimumInputLength:1,
                  multiple:true,  
  
                  query:function(query)
                   {
                      var data={results:[]};
                     console.log("input string"+query.term);  
                    data= scope.getmultiselectresult(query.term);  
                  console.log("Data"+data.results.length);//  nothing  is  return ..print  length 0
                 for(var c=0;c&lt;data.results.length;c++)
                     {
                      console.log("text"+scope.data.results.text+"id"+scope.data.results.id);
                     }
  
                  query.callback(data);
               }
          });
      }
  };}]);
  </code></pre>
  
  <p>Controller code </p>
  
  <pre><code> $scope.getmultiselectresult = function(term) {
      console.log("in controller getmultiselectresult..term" + term);
      var results = [];
      $http({
          url : "rest/getMultiSelect",
          method : "GET",
          params : {
              term : term
          }
      }).success(function(data) {
  
          console.log("data.length" + data.length + "data" + data); //fetches data correctly
  
          for (var i = 0; i &lt; data.length; i++) {
              $scope.data.results.push({
                  id : data[i].id,
                  text : data[i].text
              });
              console.log("id " + results[i].id + " name" + results[i].text);
          }
      });
  
      return results;
  };
  </code></pre>
  
  <p>My problem is, I am not able to pass data from controller to directive linker function correctly. And I also want to know how to get selected item's id and  text.</p>
  
  <p>Thanks in advance</p>