Home  >  Article  >  Web Front-end  >  Examples of advanced usage of drop-down boxes in AngularJS

Examples of advanced usage of drop-down boxes in AngularJS

小云云
小云云Original
2018-01-25 11:06:251459browse

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(&#39;myApp&#39;, []);
app.controller(&#39;myCtrl&#39;, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn