I wonder if it possibile to access statusChanges
in Angular 2 Template driven forms.
I tried the approach offered by this answer, but it doesn't work. https://stackoverflow.com/a/49666202/6920871
Should I refactor the form as Reactive or can I use another approach to emit an event when form validation status changes?
__
Current approach that does not work:
In component TS
export class FormComponent implements OnInit {
[...]
@ViewChild('myForm', { static: false }) myForm;
ngAfterViewInit() {
let c = this.myForm.statusChanges.subscribe(() => {
console.log(this.myForm.status, "Is form dirty yet: " + this.myForm.dirty);
});
}
in component template
<form #myForm>
[...]
</form>
I get a ERROR TypeError: Cannot read property 'subscribe' of undefined
at FormComponent.ngAfterViewInit (form.component.ts:27)
(also this.myForm
is defined, but no property statusChanges
)