Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown depends on other dropdown - angularjs

Tags:

angularjs

I'm having data in the form given below

   var servers =   [
           {
               "name": "server1",
               "version":
               [
                   "10.x"
               ]
           },
           {
               "name": "server2",
               "version":
               [
                   "1", "2"
               ]
           }
       ]

I want to have two drop down. First dropdown will display "name". When user selects name from the first dropdown, second dropdown should be populated with corresponding "version".

Non-working jsfiddle link: http://jsfiddle.net/fynVy/174/

like image 749
Krishna Avatar asked Dec 10 '25 07:12

Krishna


1 Answers

You need to tweak your HTML template, so that the first drop down is displaying the server name, and that the options for the 2nd drop down are based upon the versions in the selected drop down (ngModel of the first drop down).

<div ng-controller="MyCntrl">
    <select ng-model="server" ng-options="x.name for x in servers"></select>
    <select ng-model="version" ng-options="val for val in server.version"></select>
</div>

working fiddle here

like image 110
Brocco Avatar answered Dec 12 '25 01:12

Brocco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!