Home > Article > Web Front-end > Examples of advanced usage of drop-down boxes in AngularJS
This article mainly introduces the advanced usage of drop-down boxes in AngularJS. It analyzes the traversal, selection, binding, display and other functions of AngularJS drop-down boxes in the form of examples. Friends who need it can refer to it. I hope it can help everyone.
HTML text:
##
<body ng-app="myApp"> <!-- 对象内部属性遍历:x--key y---value --> <p ng-controller="myctr01"> {{sites}}<br> <select ng-model="site" ng-options="x for (x, y) in sites"></select> 选择的网址:<span>{{site}}</span> </p> <p ng-controller="myCtrl"> <p>选择一辆车:</p> <!-- 这里y标识成员元素对象,并且使用该对象的brand属性作为显示文本,select的值与y绑定 --> <select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars"></select> <p>你选择的是: {{selectedCar.brand}}</p> <p>型号为: {{selectedCar.model}}</p> <p>颜色为: {{selectedCar.color}}</p> <p>下拉列表中的选项也可以是对象的属性。</p> </p>
Javascript operation code:
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"} } //简单对象 $scope.sites = { site01 : "Google", site02 : "Baidu", site03 : "Taobao" }; }); app.controller("myctr01",function($scope){ $scope.sites = { site01 : "Google", site02 : "Baidu", site03 : "Taobao" }; });Effect: Related recommendations:
jQuery simulates drop-down box selection corresponding menu
JavaScript implements adding and deleting elements to the select drop-down box instance sharing
angularjs drop-down box implements rendering html
The above is the detailed content of Examples of advanced usage of drop-down boxes in AngularJS. For more information, please follow other related articles on the PHP Chinese website!