AngularJs’s ng-repeat allows us to traverse arrays to generate Dom elements very conveniently, but improper use can also cause performance problems. Let me share with you how to use the ng-repeat directive to implement a drop-down box in the project.
1. Problem background
The options in the select drop-down box are assembled into a drop-down box. Here, the ng-repeat instruction is used to create
2. Implementation source code
<!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. Problem description
ng-repeat instruction can repeat data
The above is the editor’s introduction to AngularJS using ng- The repeat command implements a drop-down box. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!
For more related articles about AngularJS using the ng-repeat directive to implement drop-down boxes, please pay attention to the PHP Chinese website!