[英]angular date picker issue
我正在为我的表单使用ngbdatepicker
。 我想单独保存日期。 我需要得到如下日期。
<input class="form-control ngbfield custom-form-control" required [ngClass]="{'is-invalid':f.touched && birthDay.invalid}" placeholder="yyyy-mm-dd" name="dob" [readonly]="true" #birthDay="ngModel" [(ngModel)]="signupModel.birthDay" ngbDatepicker #d1="ngbDatepicker"/>
日期成功通过。 我控制台记录了以下值。
console.log(this.signupModel.birthDay.year);
console.log(this.signupModel.birthDay.day);
console.log(this.signupModel.birthDay.month);
以上值打印正确。 但我的问题是在终端中发生了错误。 请检查我的屏幕截图。
我如何纠正这个?
好像你的birthDay
变量是用“Date”类型定义的。 原来的JS“Date”对象没有这些属性!
ngbdatepicker 使用一个简单的模型:https ://ng-bootstrap.github.io/#/components/datepicker/examples
Model: {
"year": 2020,
"month": 1,
"day": 16
}
请显示您对birthDay
类型定义。
你应该这样定义它:
signupModel: {
/* your properties here */
birthDay: { year: number, month: number, day: number }
/* more properties here */
};
现场演示: https : //stackblitz.com/edit/angular-so-4?file=app% 2Fdatepicker-basic.ts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.