To show errors when there is a statusChange or valueChange in your form, you can make use of the below 2 observables on your formGroup object.
- valueChanges: Observable --> emits an event every time the value of the control changes
- statusChanges: Observable ---> emits an event every time the validation status of the control recalculates.
form: FormGroup;
constructor(private formBuilder: FormBuilder) {}
this.form = this.formBuilder.group({
username: ['', [ Validators.required ]],
password: ['', [ Validators.required ]]
});
To monitor a single formcontrol,
this.form.get('username').valueChanges.subscribe(
result => {
// call your DialogAlertComponent to show errors if any
}
);
To monitor the entire form,
this.form.valueChanges.subscribe(
result => {
// call your DialogAlertComponent to show errors if any
}
);
Here statusChanges Observable can also be used.