0

So, I have a md-select based on a JSON I receive. These options have a "type" property that I can filter by as seen below:

$scope.data = [
    {name:"1-1",Id:1,type:1},
    {name:"2-2",Id:2,type:2}, 
    {name:"3-2",Id:3,type:2},
    {name:"4-2",Id:4,type:2},
    {name:"5-3",Id:5,type:3},
    {name:"6-3",Id:6,type:3}
];
<md-select multiple class="form-control" ng-model="selectedIds"> 
    <md-option ng-value="item.Id" ng-repeat=""item as (item.Name) for item in data">
        {{item.Name}}">
    </md-option>
</select>

But what I need is to filter the options showed in the select using the options already selected in the same dropdown. So if I select the option "3-2", the dropdown would show only "2-2, 3-2 and 4-2". How can I do that?

Pietchaki
  • 39
  • 5

1 Answers1

0

Could find a solution for this using this other question: On change, I get the selected type using a filter by the selected Id, and then use the type as filter to the options. Also, if no option selected, the "selectedType" should be set to nothing, otherwise it filtered by the first option's type.

<md-select multiple class="form-control" ng-model="selectedIds"
ng-change="selectedType=(selectedIds.length=0)?'':(data|filter:{Id:selectedIds})[0].type"> 
    <md-option ng-value="item.Id" ng-repeat="item in data | filter : selectedType">
        {{item.Name}}">
    </md-option>
</select>
Pietchaki
  • 39
  • 5