在angular中实现下拉框的两种⽅式ng-repeat和ng-option 1. ng-repeat实现下拉框:
select下拉框⾥option组装成下拉框,这⾥利⽤ng-repeat指令来创建
实现源码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AngularJS之下拉框(⽅式⼆)</title>
<script type="text/javascript"src="../js/angular.min.js"></script>
<script>
var app = dule("secondApp",[]);
$s = ["松树","樟树","枫树","枣树","桃树"];
});
</script>
</head>
<body>
angular和angularjs<div ng-app="secondApp"ng-controller="secondCon">
<select >
<option ng-repeat="tree in trees">{{tree}}</option>
</select>
</div>
</body>
</html>
<-option指令使⽤很简单,只需要绑定两个属性:
⼀个是ng-model⽤于获取选定的值;
另⼀个是ng-options⽤于确定下拉列表的元素数组。
<select ng-model="engineer.currentActivity" class="form-control" ng-options="act for act in activities"></select>
上⾯这条语句就是把选择的值与engineer.currentActivity进⾏双向数据绑定,然后列表中的选项是activities中的每⼀个值。数据如下:$ineer = {
name: "Dani",
currentActivity: "Fixing bugs"
};
$scope.activities =
[
"Writing code",
"Testing code",
"Fixing bugs",
"Dancing"
];

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。