我发现对我有用的一种方法(查看源代码)是:
this.logsearchForm = new FormGroup({
'searchString': new FormControl('', Validators.required),
'selectedApp': new FormControl(''),
'selectedUser': new FormControl(''),
'startDate': new FormControl(this.startDate, Validators.required),
'endDate': new FormControl(this.endDate)
}, {}, this.periodValidator);
下面的验证器(使用moment.js进行日期操作)
periodValidator(formGroup:FormGroup) {
let stDt = moment(formGroup.value.startDate, "MM/DD/YYYY HH:mm");
let endDt = moment(formGroup.value.endDate, "MM/DD/YYYY HH:mm");
if (stDt < endDt) {
return null;
}
else {
return {'failedDateValidation': true}
}
}