0

I have read some example in ng-options filter by value in another dropdown.

But in my case the data is in one scope.

I have try

Make:
<select ng-model="makeng" ng-options="option.id as option.display for option in makes">
    <option ng-disabled="true"  ng-selected="true" value="">Select a make</option>
</select>


Model:
<select ng-model="modelng" ng-options="option.data.name for option in makes | filter:{id:makeng}">
    <option ng-disabled="true"  ng-selected="true" value="">Select a model</option>
</select>

Plnkr: http://plnkr.co/edit/MlbBcVso57H3tyVEJa8o?p=preview

Community
  • 1
  • 1

1 Answers1

1

No need for the filter at all:

http://plnkr.co/edit/OjM1yJPYV1vQh5HRDNQ1?p=preview

Make:

<select ng-model="makeng" ng-options="option as option.display for option in makes">
    <option ng-disabled="true"  ng-selected="true" value="">Select a make</option>
</select>

Model:

<select ng-model="modelng" ng-options="option.name for option in makes[makes.indexOf(makeng)].data">
    <option ng-disabled="true"  ng-selected="true" value="">Select a model</option>
</select>
HankScorpio
  • 3,612
  • 15
  • 27
  • Thanks, @HankScorpio. But when I select `TOYOTA` the new options is not correct it should be `DATA1 DATA2` – Kanin Peanviriyakulkit May 21 '15 at 21:23
  • Ah right, I updated the answer. This version changes with value of makeng to be the full object (rather than just the id). I'd recommend that as the simplest option. – HankScorpio May 21 '15 at 21:27