dimanche 16 août 2020

How to select all checkboxes in Angular with ngFor and ngIf?

I would like to select all the checkboxes in Angular, where I have ngFor and ngIf when activating "Seleccionar todo (Select all)" and all the checkboxes of months are activated. The months are stored in an array.

html representation

      <div class="form-group row">
            <label class="col-2 col-form-label">Meses de siembra</label>
            <div class="col-8">
                <table>
                    <tr>
                        <label>
                            <input type="checkbox" ng-model name="seleccionarTodo"> Seleccionar todo
                        </label>
                    </tr>
                    <tr>
                        <td>
                            <div *ngFor="let m of mesesSiembra; let i=index">
                                <label *ngIf="i<6">
                                    <input type="checkbox" ng-model name="mes1a6"> 
                                </label>
                            </div>
                        </td>
                        <td>
                            <div *ngFor="let m of mesesSiembra; let i=index">
                                <label *ngIf="i>5">
                                    <input type="checkbox" ng-model name="mes7a12"> 
                                </label>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>



Aucun commentaire:

Enregistrer un commentaire