设置初始值 ng-options

Setting initial value ng-options

我想设置初始值,使用 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];

您不需要像以前一样添加 <option value=""></option>

ng-model设置为bannerSizes,应该是initSize

查看演示 link;

http://jsfiddle.net/srm16hhb/1/

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];
}