vendredi 15 juin 2018

Angular 2 - List of checkboxes - how to check the states of checkboxes

I am using Angular 2 + Typescript, and I've just started for a short time. I want to make a list of checkboxes and check their states.

Like in some shopping websites, checkboxes are the companies, select some and press the search button to show the products of the selected companies.

<ul class="companies">
    <li *ngFor="let company of companies">
        <input type="checkbox">
    </li>
</ul>

"companies" is an array taken from database. Each company simply has an id and a name. *ngFor will repeat the li for each element in the array. Each li contains a checkbox and a plain text.

I can't give each checkbox an id. Thus, I don't know how to check their states. I appreciate for any help.




Aucun commentaire:

Enregistrer un commentaire