I try to implement a custom Validator for my Angular 9 Form. The validation is a little bit difficult.
Because a couple of fields depends on the selection of a select input.
For example if I select option one of my select, Formfield 3 is required.
But if I select option two, Formfield 5 is required.
That's why I have writte a custom Validator:
export class FormComponent { public form: FormGroup = new FormGroup({ ... selectField: new FormControl(null, [Validators.required]), ... formField3: new FormControl(null, [this.validatorArtAende]), formField4: new FormControl(), formField5: new FormControl(null, [this.validatorArtAender]) }); validator (control: AbstractControl) => { if (this.form.value.selectField === 'option1' && control.value.length === 0) { return { required: true }; } return null; } } The issue is that this.form is unknwon (Cannot read property 'form' of undefined). So is there any option to pass the form or the value of a diffrent Control to the custom validator?