SWS-5007 / My-Experience

13 stars 0 forks source link

Angular - How to create Formgroup on Loop #11

Open SWS-5007 opened 1 year ago

SWS-5007 commented 1 year ago

How to create FormGroup on Loop?

Class


import { Component, ViewChild, OnInit, EventEmitter, Output } from "@angular/core";
import { FormBuilder, FormGroup, FormControl, FormArray } from '@angular/forms';

@Component({ selector: "", templateUrl: "", styleUrls: [""], })

export class Component implements OnInit { constructor( ) { }

manualSalesFormdata = new FormArray([]);

ngOnInit() {

}

get manualSaleEveryData() { return this.manualSalesFormdata.get("datas") as FormArray; }

onSubmit(data) { console.log('$$$$$$%%%%%%%%@@@@@@@@', data) }

for (let j = 0; j <= number; j++) {
const group = new FormGroup({
    total: new FormControl(''),
    cash: new FormControl(''),
    card: new FormControl('')
});

this.manualSalesFormdata.push(group);
}

}


>HTML

<form (ngSubmit)="onSubmit(manualSalesFormdata.value)">

Sales

Date Total Cash Card

{{date | date:'EEEE'}}

{{date | date:'dd/MM/YYYY'}}

</div>
<button type="submit" class='btn btn-success'>Sumbit</button>