Here is the answer, no custom validator required in this case:
Make your form normally without validator to begin with:
this.employerBasicsForm = this.fb.group({
tax: [''],
openDate: [''],
closeDate: [''],
});
A change method is required on both your openDate and closeDate fields:
<div><input type="text" formControlName="openDate" (change)="checkFields()" /></div>
<div><input type="text" formControlName="closeDate" (change)="checkFields()" /></div>
Then in your checkFields method:
checkFields() {
// Clear the validator every time a change occurs
this.employerBasicsForm.controls.tax.clearValidators();
// If both fields have been filled in, then make tax required
if ((this.employerBasicsForm.controls.openDate.value != null && this.employerBasicsForm.controls.closeDate.value != null))
{
this.employerBasicsForm.controls.tax.setValidators([Validators.required]);
}
// Update the validity
this.employerBasicsForm.controls.tax.updateValueAndValidity();
}