angular-ui / ui-select2

AngularJS wrapper for select2 (deprecated, use angular-ui/ui-select)
https://github.com/angular-ui/ui-select
MIT License
596 stars 443 forks source link

ui-select2 with ajax? #134

Open chicoxyzzy opened 10 years ago

chicoxyzzy commented 10 years ago

I am trying to get it work all day. Does this functionality works in angular? Can someone provide an example if so?

havelaer commented 10 years ago

Use an input tag instead of a select tag and pass in some select2 options:

<input type="hidden" ui-select2="{query: query, minimumInputLength: 3}" ng-model="select2" data-placeholder="Select a song" />

example for the query function in your controller:

$scope.query = function (query) {
  $http.get('http://ws.spotify.com/search/1/track.json', {
    params: {
      q: query.term
    }
  }).then(function(res){
    var songs = { results: [] };
    angular.forEach(res.data.tracks, function (song) {
      songs.results.push({
        text: song.artists[0].name + ' - ' + song.name,
        id: song.href
      });
    });
    query.callback(songs);
  });
};
coryfoo commented 10 years ago

I am also not able to get the ajax functionality to work, at least with multiple=true set.

The problems I see are:

asppsa commented 10 years ago

It seems to work if you revert to v0.0.4

kbanman commented 10 years ago

I believe this is related to #136 and #143