vendredi 29 juin 2018

Angular 4 using checkboxes with data that doesn't include booleans

I have an api that returns data that I need to use with checkboxes. If I am writing an Angular 4 app and my data looks like the code below:

mydata = [{name: 'Clark Kent'}, {name 'Lois Lane'}];

and my html looks like this:

<div class="members-container">
      <mat-card *ngFor="let member of mydata" class="member-card">
        <div class="card-checkbox">
          <mat-checkbox>
            <h4></h4>
          </mat-checkbox>
        </div>
      </mat-card>
</div>

In the controller, I want to use the checkboxes to select members to add to an array. If the api data returned a selected boolean it would be really easy to bind the checkbox to the array. I could manually add a selected field to the data but that extra step would slow down the data displaying on the screen. What is the best way to go about getting the checked members into my array?




Aucun commentaire:

Enregistrer un commentaire