我想设置和初始值,使用ng-options
,我的值会更改元素的高度和宽度,然后使用ng-repeat
重复,我想知道如何解决这个问题,希望你伙计们可以帮助我
HTML:
<select
ng-options="init as initSize for s.width + ' X ' + s.height s in sizes"
ng-model="bannerSizes">
<option value=""></option>
</select>
使用Javascript:
$scope.sizes = [
{ width: 320, height: 600, chatContainer: 430 },
{ width: 320, height: 320, chatContainer: 147 },
{ width: 336, height: 320, chatContainer: 147 },
{ width: 320, height: 320, chatContainer: 147 },
];
$scope.initSize = $scope.sizes[0];
答案 0 :(得分:0)
您不需要像以前那样添加<option value=""></option>
。
ng-model
设置为bannerSizes
,应为initSize
检查演示链接;
<强> HTML 强>
<div ng-controller="MyCtrl">
<select ng-options="s as (s.width + ' X ' + s.height) for s in sizes" ng-model="initSize"></select>
</div>
js
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.sizes = [{
width: 320,
height: 600,
chatContainer: 430
}, {
width: 320,
height: 320,
chatContainer: 147
}, {
width: 336,
height: 320,
chatContainer: 147
}, {
width: 320,
height: 320,
chatContainer: 147
}, ];
$scope.initSize = $scope.sizes[0];
}