简体   繁体   中英

What does [indeterminate] property exactly do in Angular Material components?

I have used ssome of the Angular Material components and there is a property called [indeterminate] that I have serached on the web, but there is not a good explanations what exactly it does. So, could you tell me what it does in the following example?

<section class="example-section">
  <mat-checkbox class="example-margin">Check me!</mat-checkbox>
  <mat-checkbox class="example-margin" [disabled]="true">Disabled</mat-checkbox>
</section>

<section class="example-section">
  <span class="example-list-section">
    <mat-checkbox class="example-margin"
                  [checked]="allComplete"
                  [indeterminate]="someComplete()"
                  (change)="setAll($event.checked)">
      {{task.name}}
    </mat-checkbox>
  </span>
  <span class="example-list-section">
    <ul>
      <li *ngFor="let subtask of task.subtasks">
        <mat-checkbox [(ngModel)]="subtask.completed"
                      [color]="subtask.color"
                      (ngModelChange)="updateAllComplete()">
          {{subtask.name}}
        </mat-checkbox>
      </li>
    </ul>
  </span>
</section>

indeterminate means that the checkbox is neither checked nor unchecked, kind of the middle.

As you can see from the docs, it looks like this:

This is often used when for example, you have a list of stuff that can be checked/unchecked, and they are grouped with a parent (eg TreeView).

The parent will be checked if all its children are checked, unchecked if all its children are unchecked and indeterminate if some of its children are checked.

The docs also have an example of that:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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