2
使用我已经添加了一个ngbDatePicker反应形式:ngBootstrap对角4的DatePicker总是需要
<input type="text"
id="business_incorp_date"
class="form-control"
formControlName="business_incorp_date"
ngbDatepicker
#incorporatedDatePicker="ngbDatepicker"
(click)="incorporatedDatePicker.toggle()"
readonly>
对于一个表单模型:
this.form = this.formBuilder.group({
id: [
0, [Validators.required]
],
// ... removed for brevity
business_type: [
'', [Validators.required]
],
business_incorp_date: [
'', [FormValidators.date] // <-- NOT REQUIRED BY MODEL
],
business_desc: [
'', [Validators.required]
]
// ...
});
但是,如果字段是空的它仍然ngInvalid为ngbDateFormat
:
{ "ngbDate": { "invalid": { "year": null, "month": null, "day": null } } }
任何人都知道如何使DatePicker字段允许一个空字符串?
参见:https://github.com/ng-bootstrap/ng-bootstrap/issues/1582#issuecomment-304204567 –