jeudi 23 août 2018

angular material checkbox using form group and formarray

I want to generate checkbox with an array

component.ts

profiles: string[] = [
    'Sales Admin',
    'Finance Admin',
    'Gateway Admin',
    'Support Admin',
  ];
profileControls: any;

//creating formcontrols
constructor() {    
    this.profileControls = this.profiles.map(c => new FormControl(false));
    this.createFormControls();
    this.createForm();
  }

createFormControls() {    
    this.userid = new FormControl('', Validators.email);
    this.accsprofile = new FormArray(this.profileControls);
}

createForm() {
    this.myform = new FormGroup({      
      userid: this.userid,      
      accsprofile: this.accsprofile
    });
  }

component.html

<div *ngFor="let profile of profileControls let i=index" >
    <mat-checkbox class="example-margin" [ngModel]="" [formControlName]="profiles[i]">
      
    </mat-checkbox>
</div>

when form submitted I am not getting checked profile data. Could anybody help me to sort out.

output enter image description here




Aucun commentaire:

Enregistrer un commentaire