TS2564: Property ‘signupForm’ has no initializer and is not definitely assigned in the constructor

  angular, angular8

I’m using ViewChild for angular form submit. This is my code,

app.component.ts

import { Component, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
    @ViewChild('f') signupForm: NgForm; 

    onSubmit(){
        console.log(this.signupForm);
    }
}

app.component.html

<form #f="ngForm" (ngSubmit)="onSubmit()" novalidate></form>

But I’m getting this error,

src/app/app.component.ts:11:21 – error TS2564: Property ‘signupForm’
has no initializer and is not definitely assigned in the constructor.

11 @ViewChild(‘f’) signupForm: NgForm;

Source: Angular Questions

One Reply to “TS2564: Property ‘signupForm’ has no initializer and is not definitely assigned in the constructor”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.