dimanche 24 octobre 2021

Not able to set checkboxes based on saved results from DB

.ts File: editUser(userData: user): void {

 let selectedProjectIdsList = userData.projectIds.split(',');

    for (let i = 0; i < selectedProjectIdsList.length; i++) {
      this.projects
        .filter((x) => x._id == selectedProjectIdsList[i])
        .map((x) => x.selected = true);

      console.log(
        this.projects
          .filter((x) => x._id == selectedProjectIdsList[i])
          .map((x) => x.selected = true)
      );
    }

}

.html File:

  <ul class="list-group list-row">
              <li class="list-group-item" *ngFor="let item of projects">
                <input
                  class="form-check-input me-1"
                  type="checkbox"
                  value="item._id"
                  (change)="onChangeProject()"
                  [(ngModel)]="item.selected"
                  name="selected"
                />
                 |  |`enter code here`
                
              </li>
            </ul>

Note : After getting API response from backend It checked all the checkboxes




Aucun commentaire:

Enregistrer un commentaire