【发布时间】:2016-08-31 14:43:40
【问题描述】:
我遇到了一个难以追踪的 ng-options 问题。我在选择控件中使用带有 ng-options 的字符串数组。它似乎可以正确跟踪,但默认月份名称未显示为页面加载下拉列表中的选定值。我创建了以下 jsfiddle 来说明这个问题:https://jsfiddle.net/risingfish/ktocfrhn/13/
Javascript:
var myApp = angular.module('momentTest', []);
myApp.controller('main', function ($scope) {
$scope.months = moment.months();
$scope.currentMonth = 7;
});
myApp.run();
标记:
<div ng-app="momentTest" ng-controller="main">
<div>
<select name="monthPicker" ng-model="currentMonth" ng-options="idx as month for (idx, month) in months">
</select>
</div>
<div>
Current month: <span ng-bind="currentMonth"></span>
</div>
</div>
我很确定这是操作员的错误,但我并没有在谷歌上搜索答案。有人有想法吗?
【问题讨论】:
标签: javascript angularjs ng-options