In ref to this question https://stackoverflow.com/questions/57707339/how-to-dynamically-use-ng-for-to-get-input-boxes-and-checkbox/57707843?noredirect=1#comment101860409_57707843
. I am able to dynamically generate div elements(comprises of input element and checkbox).
I am able to retrieve the values. But my problem is: input elements must be stored along with checkboxes that are clicked. Account(input elements) have different roles associated with them. Roles are assigned based on the checkboxes checked values.
In typescript, I want to store account and its roles together. In Angular code, If I have two accounts, I am able to fetch the values of first account values and not the second value. How to I modify ngFor to fetch multiple accounts values.
Here is the code snippet and what I have tried
Angular.html
<form (ngSubmit)="SaveRecord()" #idForm="ngForm">
<div *ngFor="let item of record.roles;let i=index">
<label for="name">AccountId</label>
<input type="text" class="form-control" [(ngModel)]="item.accountid" name="accountid" (change)="updateUser($event.target.value)" required>
<label>IT Admin</label>
<mat-checkbox [(ngModel)] = "item.ITrole" id="check2" [checked]="isChecked" name="ITcheck" (change)="checkBoxClick($event,'IT Admin')">
</mat-checkbox>
</div>
typescript.ts
record = {firstName:null,lastName:null,emailAddress:null,accountRoles:1,roles:[{accountid:null,role:null}]};
SaveRecord(){
//what should I write here to get input and checkbox values and store them in array
}
roles:[{accountid:null,role:null}]. You are looping through roles not accounts.