I need to determine whether the required validator for Address should be applied based on the value of this.type being 2.
Below is the code snippet I am using for form validation:
buildForm() {
this.orgForm = this.fb.group({
Name: [this.addUpdateModel.Name, [Validators.required]],
Id: ['', [Validators.pattern(this.constant.positiveIntegers), Validators.maxLength(6)]],
Address: [this.addUpdateModel.Address, [(this.type === 2) ? '' : Validators.required]],
});
this.orgForm.valueChanges.subscribe(data => this.onValueChanged(data));
this.onValueChanged(); // (re)set validation messages now
}
Any thoughts or suggestions?