如何在angular5中选中所有mat复选框?

如何在angular5中选中所有mat复选框?,angular,Angular,我想当我点击时全部检查检查-1,检查-2和检查-3也被检查。我该怎么做 全部检查 检查-1 检查-2 支票-3 您可以使用mat checkbox的更改事件和[checked]输入属性来实现如下检查所有功能: HTML: chkArr:boolean[]=[false,false,false]; chkAllChange(event:MatCheckboxChange){ if(event.checked){ this.chkArr = this.chkArr.ma

我想当我点击
时全部检查
<代码>检查-1
检查-2
检查-3
也被检查。我该怎么做


全部检查

检查-1 检查-2 支票-3
您可以使用
mat checkbox的更改事件和[checked]输入属性来实现如下检查所有功能:

HTML

chkArr:boolean[]=[false,false,false];

  chkAllChange(event:MatCheckboxChange){
    if(event.checked){
      this.chkArr = this.chkArr.map(m=>true);
    }
    else{
      this.chkArr = this.chkArr.map(m=>false);
    }
  }
全部检查

检查-1 检查-2 支票-3
TS

chkArr:boolean[]=[false,false,false];

  chkAllChange(event:MatCheckboxChange){
    if(event.checked){
      this.chkArr = this.chkArr.map(m=>true);
    }
    else{
      this.chkArr = this.chkArr.map(m=>false);
    }
  }

此处演示:

您可以使用
mat checkbox的更改事件和[checked]输入属性来实现如下检查所有功能:

HTML

chkArr:boolean[]=[false,false,false];

  chkAllChange(event:MatCheckboxChange){
    if(event.checked){
      this.chkArr = this.chkArr.map(m=>true);
    }
    else{
      this.chkArr = this.chkArr.map(m=>false);
    }
  }
全部检查

检查-1 检查-2 支票-3
TS

chkArr:boolean[]=[false,false,false];

  chkAllChange(event:MatCheckboxChange){
    if(event.checked){
      this.chkArr = this.chkArr.map(m=>true);
    }
    else{
      this.chkArr = this.chkArr.map(m=>false);
    }
  }

此处演示:

您可以这样做。在html中


在您的
.ts
文件中

checkAll(事件){
this.orders.forEach(object=>object.isChecked=event.target.checked);
}

您可以这样做。在html中


在您的
.ts
文件中

checkAll(事件){
this.orders.forEach(object=>object.isChecked=event.target.checked);
}