我有问题让ng-option工作。 我有一个值alarm.type,我想要$ scope.weekTypes的选项增益列表。
这是我到目前为止所做的:
$scope.weekTypes = ["null", "sunday", "monday", "tuesday", "wednesday", "thursday", "Friday", "saturday", "Week", "Week end", "All days"];
<div class="AL_box" ng-repeat="alarm in alarms">
<label for="type"> Type: </label>
<select name="type" ng-model="SelectType" ng-option="weekType as alarm.Type for weekType in weekTypes">
</select>
答案 0 :(得分:0)
我认为alarm.Type具有此警报的选定值。首先,您有一个错误,ng-option
不存在,是ng-options
,您必须将选择模型定义为alarm.Type
,因为这将是数据绑定的位置。< / p>
结果是:
<select name="type" ng-model="alarm.Type" ng-options="weekType as weekType for weekType in weekTypes">
这是jsfiddle
答案 1 :(得分:0)
好吧,你在这里做错了几件事:
as ...
中声明的内容是显示的选项,因此可以点击它:它必须是weekType
。select
元素更改alarm.type
属性,则 ngModel 需要绑定到alarm.type
ng-option
时实际需要ng-options
s 。这里有working JSFiddle你可以用作参考:)