Angular 2 Form “Cannot Find Control”

前端 未结 2 1623
走了就别回头了
走了就别回头了 2021-01-14 04:54

I am trying to use Angular 2 Forms for validation, but when I try to add more than one control. It seems like it just gets ignored. I have followed many different guides to

2条回答
  •  梦毁少年i
    2021-01-14 05:19

    I tried to create new FormGroup in my component. I've imported ReactiveFormsModule from angular/forms and added to app.module.ts imports.

    but I was getting Cannot find name 'FormGroup' and Cannot find name 'FormControl' errors

    Here is my component

    export class SignupFormComponent {
      form1 = new FormGroup({
        username: new FormControl(),
        password: new FormControl()
      });
    }
    

    Adding the below import statement in component resolved my issue.

    import { FormGroup, FormControl } from '@angular/forms';
    

    Not the answer to your question but Posting as this might help someone who faces same error.

提交回复
热议问题