我有一个选择框,我已经应用了角度选择。以下是完整的HTML
<body ng-app="myApp">
<div ng-controller="mainController">
<div ng-init="init()">
<select id="selectid1" name="selectid1" ng-model="angularselect" chosen>
<option value=""></option>
<option ng-repeat="report in reportValuesOptions" value="{{report['value']}}">{{report['name']}}</option>
</select> Value : {{angularselect}}
</div>
<input type="button" ng-click="addreport()" value="Add Report" />
</div>
</body>
选择框将从控制器范围$scope.reportValuesOptions = [];
在init
加载时调用div
函数来设置select
框中的默认值
$scope.init = function()
{
$scope.reportValuesOptions.length = 0;
$scope.reportValuesOptions.push({'name':'Previous day compasite','value':'previousdaycomposite'});
$scope.reportValuesOptions.push({'name':'ACH Customer Activity','value':'achcustomeractivity'});
}
HTML中有一个button
,当点击添加数组addReport
$scope.reportValuesOptions
函数
但点击此button
时,添加到数组的值不会反映在select
框中。这些值也应该select
框作为option