1

I have a problem. I'm trying to add input fields to mat-table but I'm having trouble. Attached is a Stackblitz link where I tried to recreate it. Unfortunately, I can't get along with the similar questions here in Stackoverflow.

https://stackblitz.com/edit/angular-tkxlgt

I'm grateful for any help or hints.

Svensen
  • 67
  • 1
  • 1
  • 7

1 Answers1

0

Ok found the solution. need to update the formarray every time i push a new object. i fixed the function:

    addLocation(value: any) {
    let location: any = this.locations.find((res) => res.street == value);
    if (this.locationsPicked.indexOf(location) === -1) {
      this.locationsPicked.push(location);
      this.formArray.push(
        new FormGroup({
          price: new FormControl(''),
          select: new FormControl(false),
        })
      );
    }
    this.locationsCtrl.setValue('');
    this.dataSource.data = this.locationsPicked;
  }

PS: i improved my stackblitz example with the solution https://stackblitz.com/edit/angular-tkxlgt

Svensen
  • 67
  • 1
  • 1
  • 7