下拉框默认的值为 key-value 对中的 value ,也可以用 as 来修改下拉框的值。
也就是 x for (x, y) 相当于是 y as x for (x, y)。
as 前面的为下拉框的值,后面的为下拉框显示的内容。
也可以不使用key-value 对中的 value 作为下拉框的值, 直接使用对象的属性,代码示例:
使用 ng-options 创建下拉列表,选中的值是一个对象:
你选择的是: {{selectedSite}}
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.sites = {
site01 : {site : "Google", url : "http://www.google.com"},
site02 : {site : "Runoob", url : "https://www.runoob.com"},
site03 : {site : "Taobao", url : "http://www.taobao.com"}
};
$scope.selectedSite = $scope.sites.site02.url; //设置第2个为初始值;
});
kindaries
kindaries
kin***ies@qq.com2年前 (2018-10-08)