mardi 6 octobre 2020

Angular Check checkboxes on load

need your help

I have an array of checkbox values

colors = ['Black', 'Red', 'White', 'Blue', 'Yellow', 'Grey'];

Implemented them in HTML

<div *ngFor="let color of colors; let i = index" class="checkbox">
        <label>
          <input type="checkbox" class="colors" [value]="color" (change)="addCheckboxData($event)" />
          
        </label>
      </div>

So it looks like this: enter image description here

I have an array of values that should be checked when I load the page

  checkedValues = ['Black', 'White', 'Grey'];

I added them to formarray

color: this._formBuilder.array(this.checkedValues),

It works and color formarray have values like in checkedValues array: enter image description here

But checkboxes are not checked so I want this values to be displayed as checked. How can I do this? Thank You




Aucun commentaire:

Enregistrer un commentaire