I need to detect real time changes to the fields of a FormGroup. I have a simple parent-child components structure as follows:
parent component view
<my-child [myForm]="myForm"></my-child>
child component controller
@Input()
myForm: FormGroup;
ngOnChanges(changes: SimpleChanges) {
console.log('changes', changes)
}
The problem is that no change is detected when the form fields change. Is there a way to trigger the ngOnChanges to any form change?
Thanks.
You can use the following:
this.myForm.valueChanges.subscribe(changes => {
// do what you need with the form fields here
// you can access a form field via changes.fieldName
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With