Angular Material 复选框组件的 API 参考

import {MatCheckboxModule} from '@angular/material/checkbox';

选择器: mat-checkbox

Exported as: matCheckbox
属性
名称 描述
@Input('aria-describedby')

ariaDescribedby: string

'aria-describedby' 属性是在该元素的标签和字段类型之后读取的。

@Input('aria-label')

ariaLabel: string

附着在宿主元素的 aria-label 属性上。在大多数情况下,aria-labelledby 优先,所以这个可以省略。

@Input('aria-labelledby')

ariaLabelledby: string | null

用户可以指定 aria-labelledby 属性,它会被转发到 input 元素

@Input({ transform: booleanAttribute })

checked: boolean

是否勾选了复选框。

@Input()

color: string | undefined

复选框的调色板颜色。

@Input({ transform: booleanAttribute })

disableRipple: boolean

复选框是否具有波纹效果。

@Input({ transform: booleanAttribute })

disabled: boolean

该复选框是否已禁用。

@Input()

id: string

复选框的唯一 ID。如果没有提供,它就会自动生成。

@Input({ transform: booleanAttribute })

indeterminate: boolean

该复选框是否未决。这也称为“混合”模式,用于表示带有三种状态的复选框,例如一个嵌套着其它复选框列表的复选框。请注意,只要手动点击复选框,就会立即将未决状态设为 false。

@Input()

labelPosition: 'before' | 'after'

标签位于复选框之后还是之前。默认为 'after'

@Input()

name: string | null

如果存在,name 值就会被应用到 input 元素中

@Input({ transform: booleanAttribute })

required: boolean

该复选框是否必填的。

@Input()

value: string

原生输入框元素的 value 属性

@Output()

change: EventEmitter<MatCheckboxChange>

checked 值发生变化时会发出本事件。

@Output()

indeterminateChange: EventEmitter<boolean>

indeterminate 值发生变化时会发出本事件。

inputId: string

返回不可见输入框的唯一 id。

Deprecated

ripple: MatRipple

引用复选框的 MatRipple 实例。

方法
focus

聚焦复选框。

registerOnValidatorChange
参数

fn

() => void

toggle

切换 checked 状态。

validate
参数

control

AbstractControl<boolean, boolean>

返回值
ValidationErrors | null

一个验证器,用于验证 Material 复选框在模板驱动复选框中的必填属性。目前 CheckboxRequiredValidator 只能用于 input type=checkbox,而且不能用于 mat-checkbox

选择器: mat-checkbox[required][formControlName] mat-checkbox[required][formControl] mat-checkbox[required][ngModel]

Deprecated
属性
名称 描述

required: boolean | string

跟踪绑定到此指令的 required 属性的更改。

方法
enabled
参数

input

boolean

返回值
boolean

registerOnValidatorChange
参数

fn

() => void

validate
参数

control

AbstractControl<any, any>

返回值
ValidationErrors | null

MatCheckbox 发出的“更改”事件对象。

属性
名称 描述

checked: boolean

该复选框的新 checked 值。

source: MatCheckbox

该事件的来源 MatCheckbox。

默认的 mat-checkbox 选项,可以改写它们。

属性
名称 描述

clickAction: MatCheckboxClickAction

复选框的默认复选框单击操作。

color: ThemePalette

用于复选框的默认主题调色板。

当用户点击 input 元素时,复选框会处理点击动作。 noop:不要切换为勾选或未决。 check:只切换勾选状态,忽略未决状态。 check-indeterminate:切换勾选状态,未决状态设为 false。默认行为。 undefined:与 check-indeterminate 相同。

type MatCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' | undefined;
Deprecated
const MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR: any;

这个注入令牌用来改写 mat-checkbox 的默认选项。

const MAT_CHECKBOX_DEFAULT_OPTIONS: InjectionToken<MatCheckboxDefaultOptions>;
Deprecated
const MAT_CHECKBOX_REQUIRED_VALIDATOR: Provider;