簡體   English   中英

角度日期選擇器問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM