0

In angular 7, I am trying to develop a page where i will be showing data in table format , and also want to give user access to edit, add and delete. I am facing problem in adding formarray to the formgroup. On console i am getting below error,

ERROR Error: formGroup expects a FormGroup instance. Please pass one in.

I have added formgroup but it is not showing as per expectation. I also created stackblitz for issue.

Thanks in advance.

usersam
  • 1,125
  • 4
  • 27
  • 54

2 Answers2

2

You need to inject FormBuilder as a dependency,

Instead of private fb: FormBuilder;

Add it to the constructor as follows:

constructor(private fb: FormBuilder) { }

Slackblitz

Documentation

Akshay Rana
  • 1,455
  • 11
  • 20
0

Maybe you forgot to initialize FormGroup on ngOnInit:

this.UserForm = new FormGroup({
       firstName: new FormControl()
    });

Firstname is only an example, there you need to define your fromControls, just like this:

  ngOnInit() {    
      this.getdata();

      this.UserForm = new FormGroup({
        page: new FormControl(),
        per_page: new FormControl(),
        total: new FormControl(),
        total_pages: new FormControl(),       
        UserArray: this.fb.array([])
        });    
  }  
anexo
  • 495
  • 1
  • 11
  • 22