How to select all/trigger/unselect checkbox in Angular without use FormArray and ngModel

.html:



......
            
              [checked]="item.checkbox_value">

              

.ts:

export interface NewXxxModel extends XxxModel {
  checkbox_value?: boolean;
}
....

  not_assigned_tasks: NewXxxModel[];
  new_tasks_ary: Array = [];

....

  triggerAll(tasks: string, event: any) {

    if (tasks == 'not_assigned_tasks') {
      this.new_tasks_ary = [];
      for (var i = 0; i < this.not_assigned_tasks.length; i++) {
        if (event && event.target.checked == false) {
          this.not_assigned_tasks[i].checkbox_value = false;
        } else {
          this.not_assigned_tasks[i].checkbox_value = true;
          this.new_tasks_ary.push(this.not_assigned_tasks[i].id);
        }
      }
    }
    console.log(this.new_tasks_ary);
  }

.....

          let f = document.getElementById('not_assigned_tasks_checkbox');
          f.checked = false;

Leave a Reply

Your email address will not be published. Required fields are marked *