I would like to add an item to an array whenever a check box is checked in *ngFor I am looking for a neat way of doing this without too much code or using a component method. I know this used to be really easy in angular version 1
<tr *ngFor="let this_user of RoleUsers.Users">
...
<input type="checkbox" class="custom-control-input" [(ngModel)]="UsersToRemove.Users[this_user.id]" /> <!--[(ngModel)]="" --> <!-- ng-false-value="expression"-->
..
</tr>
For this code I get the error ERROR TypeError: Cannot read property '13' of undefined
so I think I am very close.
At the moment I am using the user ids to track the keys but if I could have a nice array. If this is not possible without a component method please provide an example.
Update I have managed to get this working with fewer code;
<input type="checkbox" class="custom-control-input" (change)="AddOrRemoveUser(this_user, $event.target.checked)" />
Then the method;
AddOrRemoveUserToRemove (user, checked) {
console.log ("Remove or add: ", user, checked);
}
I think this this the quickest way to do it.
The UsersToRemove object looks like this;
class UsersToRemove {
Users: any[];
InAction: boolean = false;
}
This is attached to the actual component.