我有一系列日期,必须在选择标记中显示
视图:
<select id="select" name="select" class="form-control"
ng-model="files.options.fechaIngreso"
ng-change="files.fechaIngresoChanged()"
ng-options="date.item for date in files.dates track by date.id">
</select>
控制器:
var self = this, data = 4;
self.dates = [];
for (var i =data; i >= 0; i--) {
var historicalDate = moment().subtract(i, 'days').format("DD/MM/YYYY");
var obj = {
item: historicalDate,
id: i
};
self.dates.push( obj );
}
并收到此错误:
TypeError: undefined is not a function
at render (file:///android_asset/www/lib/angular/angular.js:26098:24)
at Scope.$digest (file:///android_asset/www/lib/angular/angular.js:14358:36)
at file:///android_asset/www/lib/angular/angular.js:14505:26
at completeOutstandingRequest (file:///android_asset/www/lib/angular/angular.js:4924:10)
at file:///android_asset/www/lib/angular/angular.js:5312:7
访问.prop('selected',option.selected)时执行失败
(文件:///android_asset/www/lib/angular/angular.js:26098:24)
(element = optionTemplate.clone())
.val(option.id)
.prop('selected', option.selected)
.attr('selected', option.selected)
.prop('label', option.label)
.text(option.label);
这种情况也不起作用
<select id="select" name="select" class="form-control"
ng-model="files.options.fechaIngreso"
ng-change="files.fechaIngresoChanged()"
ng-options="date for date in files.dates track by date">
</select>
var self = this, data = 4;
self.dates = [];
for (var i = data; i >= 0; i--) {
var historicalDate = moment().subtract(i, 'days').format("DD/MM/YYYY");
self.dates.push( historicalDate );
}
有相同的错误
答案 0 :(得分:0)
我找到了一个解决方案,不是最佳实践解决方案,而是实用解决方案
<option ng-repeat="date in files.dates" ng-selected="date == files.options.fechaIngreso" value="{{date}}">{{date}}</option>