角度选择和ng选项绑定

时间:2015-11-29 20:47:44

标签: angularjs ng-options

我有问题让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>

2 个答案:

答案 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)

好吧,你在这里做错了几件事:

  1. as ...中声明的内容是显示的选项,因此可以点击它:它必须是weekType
  2. 如果您希望select元素更改alarm.type属性,则 ngModel 需要绑定到alarm.type
  3. 您使用ng-option时实际需要ng-options s
  4. 这里有working JSFiddle你可以用作参考:)

相关问题