Reputation: 479
I am trying to access the class names of Form and its controls in the Typescript file. Is it possible? Please check the Code : https://stackblitz.com/edit/angular-ivy-ps9aeb
ngOnInit(): void {
console.log(this.ModelForm.form.controls.firstName?.valid);
}
The above code is giving error
Error in src/app/app.component.ts (11:22)
Property 'ModelForm' does not exist on type 'AppComponent'.
Upvotes: 0
Views: 977
Reputation: 5813
You need to use @ViewChild
to have access to the template driven form in your typescript file.
export class AppComponent implements OnInit {
@ViewChild('ModelForm')
public ModelForm: NgForm;
//...
}
Upvotes: 2