简体   繁体   English

angular mat-checkbox 需要点击两次才能取消选中和选中

[英]angular mat-checkbox need two clicks to uncheck and check

I have check-boxes, that populating dynamically, but issue when trying to unselected the check box it asks two clicks to uncheck the checkbox.我有复选框,可以动态填充,但是在尝试取消选中复选框时会出现问题,它要求单击两次以取消选中复选框。

enter code here
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
        <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle matTreeNodePadding>
          <button mat-icon-button disabled></button>
          <mat-checkbox class="checklist-leaf-node"
                        [checked]="checklistSelection.isSelected(node)"
                        (change)="checklistSelection.toggle(node);">{{getValue(node)}}</mat-checkbox>
        </mat-tree-node>



        <mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
          <button mat-icon-button matTreeNodeToggle
                  [attr.aria-label]="'toggle ' + node.filename">
            <mat-icon class="mat-icon-rtl-mirror">
              {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
            </mat-icon>
          </button>
          <mat-checkbox [checked]="descendantsAllSelected(node)"
                        [indeterminate]="descendantsPartiallySelected(node)"
                        (change)="todoItemSelectionToggle(node)">{{getValue(node)}}</mat-checkbox>

        </mat-tree-node>
      </mat-tree>

Default mat-checkbox options that can be overridden.可以覆盖的默认mat-checkbox选项。

Checkbox click action when user click on input element.当用户单击输入元素时复选框单击动作。 noop: Do not toggle checked or indeterminate. noop:不要切换选中或不确定。 check: Only toggle checked status, ignore indeterminate. check:只切换选中状态,忽略不确定。 check-indeterminate: Toggle checked status, set indeterminate to false. check-indeterminate:切换选中状态,将不确定设置为false。 Default behavior.默认行为。 undefined: Same as check-indeterminate.未定义:与检查不确定相同。

type MatCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' | undefined;

Injection token that can be used to specify the checkbox click behavior.可用于指定复选框单击行为的注入令牌。

const MAT_CHECKBOX_CLICK_ACTION: InjectionToken<MatCheckboxClickAction>;

Hope this concept will help to solve your problem希望这个概念将有助于解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM