【发布时间】:2017-01-22 07:44:48
【问题描述】:
我收到此错误The ng-model for md-datepicker must be a Date instance. Currently the model is a: string。我正在使用时刻..
在视图中
<md-datepicker ng-model="Model.currentContact.getSetIncorporated" ng-model-options="{ getterSetter: true }" md-placeholder="Enter date"></md-datepicker>
在模型中
Contact.prototype.getSetIncorporated = function(date) {
if (arguments.length) {
this.company.information.incorporatedObject = date;
this.company.information.incorporated = moment.utc(date).format('X');
}
if (!this.company.information.incorporatedObject) {
if (this.company.information.incorporated !== '') {
this.company.information.incorporatedObject = moment.utc(this.company.information.incorporated, 'X').toDate();
} else {
this.company.information.incorporatedObject = null;
}}
return this.company.information.incorporatedObject;
}
我也尝试了几个 mdLocale.formatDate 和 parseDate。当前版本是
$mdDateLocale.formatDate = function(date) {
return moment(date).format('YYYY/MM/DD');
};
$mdDateLocale.parseDate = function(dateString) {
var m = moment(dateString, 'YYYY/MM/DD', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
服务器正在发送这个字符串2016-09-10T22:00:00.000Z
当我使用 new Date() 将该字符串转换为 Date 对象时,我在 mdDatePicker 中得到了正确的结果,但我也得到了
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
这会破坏我的页面。
【问题讨论】:
标签: javascript angularjs datepicker angular-material