AngularJS filter multiple select inputs

4,676 views
Skip to first unread message

Jeffrey Jones

unread,
Mar 6, 2013, 6:47:52 PM3/6/13
to ang...@googlegroups.com

I need to filter out select options that include the current item. The question is how can I splice out each options as we iterate through the items coming to our filter, and return the proper results for each select in the list being filtered.

Please check my full question here:

any help is greatly appreciated! 

Clint Checketts

unread,
Mar 6, 2013, 7:31:44 PM3/6/13
to ang...@googlegroups.com
Answered here: http://stackoverflow.com/a/15260900/970308

The select directive has an ng-options attribute: http://docs.angularjs.org/api/ng.directive:select

<select ng-model='selectedCountry' ng-options='country.name for country in filteredCountries()'></select>


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jeffrey Jones

unread,
Mar 6, 2013, 10:53:08 PM3/6/13
to ang...@googlegroups.com
This still doesnt work in the scenario I'm trying to achieve. the select2 dropdowns need to grab keywords and dump them into a different model, I have to use the model for this

Jeffrey Jones

unread,
Mar 6, 2013, 10:56:58 PM3/6/13
to ang...@googlegroups.com
and the docs specifically state that the ui-select2 is incompatible with ng-options. 

Clint Checketts

unread,
Mar 6, 2013, 11:00:58 PM3/6/13
to ang...@googlegroups.com
Feel free to add to the plunkr I started: http://plnkr.co/edit/cRBdkE3akCeBXYqfyHFO (click 'fork' to add your changes)

Add in the select2 ui and any other requirements and let's see what we can do.

Clint Checketts

unread,
Mar 7, 2013, 12:43:08 AM3/7/13
to ang...@googlegroups.com
Good point about select2 not working with ng-options.

Here is a plnkr with select2. I tweaked the solution to use a watch, but it is similar: http://plnkr.co/edit/Hmt1OXYvtHOAZPzW7YK3?p=preview

  $scope.$watch('version1model',function(){
    $scope.filteredItems = [];
    angular.forEach($scope.items, function(val, key){
      if(val.id != $scope.version1model){
        this.push(val);
      }
    },$scope.filteredItems);
  });

Reply all
Reply to author
Forward
0 new messages