我有表单,我想在提交时验证日期字段,我正在使用表单生成器,我该怎么做(角度方式)?另一个问题为什么我看不到日期字段中的值 published_date ?我试图搜索,但找不到输入日期字段的解决方案。
unamePattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
ngOnInit() {
this.book =
{
id: 55,
author_name : "vv",
published_date : new Date('01/02/2018'),
title : "cc"
};
this.form = this.formBuilder.group({
title : ['', Validators.required],
author : ['', Validators.required],
datePublish: ['', Validators.pattern(this.unamePattern)],
}
);
}
<input
[(ngModel)]="book.published_date"
id="dateOfBirth"
class="form-control"
placeholder="yyyy-mm-dd"
name="dp"
ngbDatepicker
formControlName="datePublish"
#dp="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary" (click)="dp.toggle()" type="button">
<i class="fa fa-calendar" aria-hidden="true"></i>
</button>
</div>