Dependent Dropdown list with Angular JS

angular-dropdown

Sharing is caring!

Here the simple Angular JS  tutorial  on creating Dependent DropDownList with Angular JS.

{code type=php}
<!DOCTYPE html>
<html>
        <head>
        <script type=“text/javascript” src=“http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js”></script>
        <script>
            function  CountryController($scope) {
                $scope.countries = {
                    ‘India’: {
                        ‘Andhra Pradesh’: [‘Vijayawada’, ‘Guntur’, ‘Nellore’, ‘Kadapa’],
                        ‘Madhya Pradesh’: [‘Hyderabad’, ‘Warangal’, ‘Karimnagar’],  
                    },
                    ‘USA’: {
                      ‘San Francisco’: [‘SOMA’, ‘Richmond’, ‘Sunset’],
                      ‘Los Angeles’: [‘Burbank’, ‘Hollywood’]
                    },
                    ‘Australia’: {
                        ‘New South Wales’: [‘Sydney’,‘Orange’,‘Broken Hill’],
                        ‘Victoria’: [‘Benalla’,‘Melbourne’]
                    }
                };
            }
        </script>
        </head>
        <body>
        <div ngapp class=“container”>
          <div ngcontroller=“CountryController”>
            <div class=“form-group”>
              <label class=“control-label” for=“Country”>Country:</label>
              <select class=“form-control input-lg” id=“country” ngmodel=“states” ngoptions=“country for (country, states) in countries”>
                <option value=>Select</option>
              </select>
            </div>
            <div class=“form-group”>
              <label class=“control-label” for=“States”>States:</label>
              <select class=“form-control input-lg” id=“state” ngdisabled=“!states” ngmodel=“cities” ngoptions=“state for (state,city) in states”>
                <option value=>Select</option>
              </select>
            </div>
            <div class=“form-group”>
              <label class=“control-label” for=“City”>City:</label>
              <select class=“form-control input-lg” id=“city” ngdisabled=“!cities || !states” ngmodel=“city” ngoptions=“city for city in cities”>
                <option value=>Select</option>
              </select>
            </div>
          </div>
        </div>
</body>
</html>
{/code}

 

Sharing is caring!