Answer the question
In order to leave comments, you need to log in
How to make an active option in a filtered select?
There are two selects, one depends on the other, how to get a filtered list in the controller, and make the first option active
Answer the question
In order to leave comments, you need to log in
Sketched on the knee.
Something like this ( DEMO ).
angular.module('toster', [])
.controller('DemoCtrl', function() {
var vm = this;
vm.type = 'fruits';
vm.types = ['fruits', 'vegetables'];
vm.fruits = ['apple', 'orange', 'banana'];
vm.vegetables = ['potato', 'tomato', 'cucumber'];
});
<body ng-controller="DemoCtrl as demo">
<div>
<select ng-model="demo.type" ng-options="type as type for type in demo.types">
</select>
<p>
Selected: <span ng-bind="demo.type"></span>
</p>
</div>
<div>
<select ng-model="demo.value" ng-options="item as item for item in demo[demo.type]">
</select>
<p>
Selected: <span ng-bind="demo.value"></span>
</p>
</div>
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question