ngForm variable coming as undefined in component

I have created a form in angular , and used template driven approach to control it . Have used ngForm in the group , and tried to access form fields via name , but i get an error in the console referring – this.form is undefined .

My html looks like –

<form #createProjectForm="ngForm" (ngSubmit)="save()">
.....
 <mat-form-field appearance="outline">
              <mat-label>NMC/ODA Project No</mat-label>
              <input name="nmcNumbber" matInput autocomplete="off" />
            </mat-form-field>

And in the component file –

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

@Component({
  selector: 'app-create-project-details-fields',
  templateUrl: './create-project-details-fields.component.html',
  styleUrls: ['./create-project-details-fields.component.scss']
})
export class CreateProjectDetailsFieldsComponent implements OnInit {
  
  @ViewChild('createProjectForm') createForm : NgForm;
  constructor() { }

  ngOnInit(): void {
    this.getFormStatus();
  }

getFormStatus(){
  this.createForm.controls['nmcNumbber'].disable();
}

But the console gives –

enter image description here

Can anyone help me out in this ? TIA

141 thoughts on “ngForm variable coming as undefined in component”

  1. It is perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or tips. Perhaps you could write next articles referring to this article. I want to read even more things about it!

    Reply
  2. Pingback: sildenafil 50mg
  3. Pingback: viagra buy
  4. Pingback: drugs like cialis
  5. Pingback: get cialis online
  6. Pingback: viagra for sale
  7. Pingback: herbal viagra
  8. Pingback: cialis viagra
  9. Pingback: purchase viagra
  10. Pingback: cialis mg
  11. Pingback: tadalafil mylan
  12. Pingback: tadalafil citrate
  13. Pingback: viagra tablets
  14. Pingback: sildenafil online
  15. Pingback: viagra otc
  16. Pingback: viagra women
  17. Pingback: viagra pour homme
  18. Pingback: viagra price
  19. Pingback: viagra prices
  20. Pingback: homemade viagra
  21. Pingback: viagra users group
  22. Pingback: buy viagra
  23. Pingback: viagra pill
  24. Pingback: hims sildenafil
  25. Pingback: online viagra
  26. Pingback: sildenafil pills
  27. Pingback: sildenafil prices
  28. Pingback: cialis generico
  29. Nice weblog here! Also your web site a lot up fast! What web host are you using? Can I get your associate link for your host? I desire my website loaded up as quickly as yours lol

    Reply
  30. I just could not depart your web site before suggesting that I actually enjoyed the standard info a person provide for your visitors? Is gonna be back often in order to check up on new posts

    Reply
  31. I carry on listening to the newscast lecture about receiving boundless online grant applications so I have been looking around for the best site to get one. Could you tell me please, where could i acquire some?

    Reply

Leave a Comment