时间:2021-01-22 12:29:05 | 栏目:AngularJS | 点击:次
AngularJs 的 ng-repeat 让我们非常方便的遍历数组生成 Dom 元素,但是使用不当也会有性能问题。下面给大家分享在项目中使用ng-repeat指令实现下拉框。
1、问题背景
select下拉框里option组装成下拉框,这里利用ng-repeat指令来创建
2、实现源码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS之下拉框(方式二)</title> <script type="text/javascript" src="../js/angular.min.js" ></script> <script> var app = angular.module("secondApp",[]); app.controller("secondCon",function($scope){ $scope.trees = ["松树","樟树","枫树","枣树","桃树"]; }); </script> </head> <body> <div ng-app="secondApp" ng-controller="secondCon"> <select style="width: 200px;"> <option ng-repeat="tree in trees">{{tree}}</option> </select> </div> </body> </html>
3、问题说明
ng-repeat指令可以重复数据