Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

angular select and dropdown-(ng-options)

<!doctype html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
  </head>
  <body>
      
<!-- Angular Dropdown by ng-options-->
<!--<div ng-app="myApp" ng-controller="myCtrl">-->
<!--    <select ng-model="selectname" ng-options="x for x in names"></select>-->
<!--</div>-->

<!-- Angular Dropdown by ng-repeat-->
<!--<div ng-app="myApp" ng-controller="myCtrl">-->
<!--    <select>-->
<!--        <option>Select</option>-->
<!--        <option ng-repeat="x in names">{{x}}</option>-->
<!--    </select>-->
<!--</div>-->
<!--<script>-->
<!--    var app = angular.module('myApp', []);-->
<!--    app.controller('myCtrl', function($scope){-->
<!--        $scope.names = ["EMIL","APNS","NEON"]-->
<!--    });-->
<!--</script>-->

<!--data binding with select options. -->

<div ng-app="myApp" ng-controller="myCtrl">

<p>Select a car:</p>

<!--<select ng-model="selectedCar">-->
<!--<option ng-repeat="x in cars">{{x.model}}&nbsp;{{x.color}}</option>-->
<!--</select>-->

<!--Use Of object as data source for dropdown list -->
<!--<select ng-model="selectedCar" ng-options="x for (x, y) in cars">-->
<!--</select>-->

<!--dropdown list can also be a property of the value object-->
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars">
</select>


<h1>You selected: {{selectedCar.brand}}</h1>
<h2>Model: {{selectedCar.model}}</h2>
<h3>Color: {{selectedCar.color}}</h3>

</div>

<!--<script>
// var app = angular.module('myApp', []);
// app.controller('myCtrl', function($scope) {
//     // $scope.cars = [
//     //     {model : "Ford Mustang", color : "red"},
//     //     {model : "Nissan GTR", color : "white"},
//     //     {model : "RangeRover", color : "black"}
//     // ];
//      $scope.cars = {
//         carA : "Ford Mustang",
//         carB : "Nissan GTR",
//         carC : "Range Rover"
//     }
// });
 </script>-->

<!--dropdown list can also be a property of the value object-->
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.cars = {
        car01 : {brand : "Ford", model : "Mustang", color : "red"},
        car02 : {brand : "Fiat", model : "500", color : "white"},
        car03 : {brand : "Volvo", model : "XC90", color : "black"}
    }
});
</script>

  </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.