Angular 2: formGroup expects a FormGroup instance. Please pass one in

前端 未结 5 851
名媛妹妹
名媛妹妹 2020-12-24 04:58

I am creating a form in Angular 2. My goal is to get data from the API and pass it into the form for editing purposes. However, I am running into this error:

5条回答
  •  没有蜡笔的小新
    2020-12-24 05:28

    Guys who face issues with reactive forms First in your component.ts file make sure you import the following:

    import { FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
    
    export class NewsfeedformComponent implements OnInit {
    
    NewsfeedForm: FormGroup;
    constructor(private _formBuilder: FormBuilder){}
    
     ngOnInit() {
    
    this.lookupService.getStatus().subscribe((status: IStatus) => {
      this.status = status;
    });
    
    this.NewsfeedForm = this._formBuilder.group({
      NewsfeedID: [0,null],
      StatusID: ['', Validators.required],
      publishdate: ['', Validators.required]
      })
     }
    
    }
    

    in your component html file

                 
    Status {{itemofStatus.Status}}

提交回复
热议问题