如何获取 angular 中复选框的选中和未选中值

How do I get the checked and unchecked values of a checkbox in angular

我有一个复选框列表,如下所示:

 <div class="col-md-4 md-padding"  *ngFor="let node of nodeList; let j=index;">
              <md-checkbox-group>
                <md-checkbox
                  class="md-h6 row md-padding--xs"
                  name="{{node.FQDN}}"
                  label="{{node.FQDN}}"
                  value="{{node.FQDN}}"
                  required="true"
                  htmlId="filter_label_{{j}}"
                  (click)="updatefilter(node.FQDN)"
                  [formControlName]="servers"
                  [(ngModel)]="node.selected">
                </md-checkbox>


              </md-checkbox-group>


            </div>

我必须检查复选框是否已选中或未选中。我该如何进行?

编辑1:节点数组对象具有以下属性:

    [
    {
    DNSResolved: "true",
    FQDN: "sa-103.abc.com",
    HostName: "sa-103",
    Role: " Voice/Video",
    productTypeId: "1"
    },

   {
    DNSResolved: "true",
    FQDN: "sa-104.abc.com",
    HostName: "sa-104",
    Role: " Voice/Video",
    productTypeId: "1"
    },

   {
    DNSResolved: "true",
    FQDN: "sa-105.abc.com",
    HostName: "sa-105",
    Role: " Voice/Video",
    productTypeId: "1"
    }

节点本身好像没有选择属性,先在节点接口或节点对象上创建一个。

其次在复选框上添加 change 事件,只要用户点击复选框更改就会被调用,您可以切换 node.selected 的值。

在 Html 文件中:

 <md-checkbox
                  class="md-h6 row md-padding--xs"
                  name="{{node.FQDN}}"
                  label="{{node.FQDN}}"
                  value="{{node.FQDN}}"
                  required="true"
                  htmlId="filter_label_{{j}}"
                  (click)="updatefilter(node.FQDN); updateSelection(node)"
                  [(ngModel)]="node.selected">
                </md-checkbox>

在 TS 文件中:

public updateSelection(node) {
     // update the values to make them persistent
     node.selected = node.selected ? false : true;
}