P
P
pontiac3582015-08-03 19:05:23
Angular
pontiac358, 2015-08-03 19:05:23

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

1 answer(s)
M
Mikhail Osher, 2015-08-03
@miraage

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 question

Ask a Question

731 491 924 answers to any question