Angular Material chips API 参考文档
import {MatChipsModule} from '@angular/material/chips';
指令
MatChipList
一种 Material Design 纸片组件(由于类似于 List 组件,因此得名 ChipList)。
A material design chips component (named ChipList for its similarity to the List component).
属性
名称 | 描述 |
---|---|
@Input('aria-orientation')
|
纸片列表的方向。 Orientation of the chip list. |
@Input()
|
用来比较选项值和当前选择的函数。第一个参数是选项的值,第二个选定的值。应该返回一个布尔值。 A function to compare the option values with the selected values. The first argument is a value from an option. The second is a value from the selection. A boolean should be returned. |
@Input()
|
用于控制何时显示错误信息的对象。 An object used to control when error messages are shown. |
@Input()
|
是否允许用户选择多个纸片。 Whether the user should be allowed to select multiple chips. |
@Input()
|
这个纸片列表是否可以选择。当纸片列表不可选时,纸片列表中所有纸片的选定状态总会被忽略。 Whether or not this chip list is selectable. When a chip list is not selectable, the selected states for all the chips inside the chip list are always ignored. |
@Output()
|
当纸片列表当前选择被用户改变时发出的事件。 Event emitted when the selected chip list value has been changed by the user. |
|
所有子纸片的失焦事件的组合流。 Combined stream of all of the child chips' blur change events. |
|
所有子纸片的聚焦事件的组合流。 Combined stream of all of the child chips' focus change events. |
|
所有子纸片的删除事件的组合流。 Combined stream of all of the child chips' remove change events. |
|
所有子纸片的选定状态更改事件的组合流。 Combined stream of all of the child chips' selection change events. |
|
这个纸片列表中包含的纸片组件。 The chip components contained within this chip list. |
|
|
|
这个纸片列表中是否存在任何拥有焦点的纸片或 matChipInput。 Whether any chips or the matChipInput inside of this chip-list has focus. |
|
ARIA 的角色,应用于纸片列表中。 The ARIA role applied to the chip list. |
|
纸片列表中选定纸片的数组。 The array of selected chips inside chip list. |
|
方法
focus | |
---|---|
让这个纸片列表中的第一个非禁用纸片获得焦点,或在没有合格纸片时让其关联输入框获得焦点。 Focuses the first non-disabled chip in this chip list, or the associated input when there are no eligible chips. |
|
参数 Parameters |
|
options? FocusOptions
|
|
registerInput | |
---|---|
将 HTML 输入框元素与该纸片列表关联起来。 Associates an HTML input element with this chip list. |
|
参数 Parameters |
|
inputElement MatChipTextControl
|
|
updateErrorState |
---|
MatChip
Material Design 风格的纸片组件。在 MatChipList 组件中使用。
Material design styled Chip component. Used inside the MatChipList component.
属性
名称 | 描述 |
---|---|
@Input()
|
Theme color palette for the component. |
@Input()
|
Whether ripples are disabled. |
@Input()
|
该纸片是否被禁用了。 Whether the chip is disabled. |
@Input()
|
确定该纸片是否显示移除样式并发出 (removed) 事件。 Determines whether or not the chip displays the remove styling and emits (removed) events. |
@Input()
|
该纸片是否可以选择。当纸片不可选时,总会忽略对选定状态的更改。默认情况下,纸片是可选择的,如果它的父纸片列表不可选,它就会变得不可选。 Whether or not the chip is selectable. When a chip is not selectable, changes to its selected state are always ignored. By default a chip is selectable, and it becomes non-selectable if its parent chip list is not selectable. |
@Input()
|
该纸片是否被选定。 Whether the chip is selected. |
@Input()
|
该纸片的值。默认为 The value of the chip. Defaults to the content inside |
@Output()
|
当该纸片被销毁时会触发。 Emitted when the chip is destroyed. |
@Output()
|
当要移除某个纸片时会触发。 Emitted when a chip is to be removed. |
@Output()
|
该纸片被选定或取消选定时会触发。 Emitted when the chip is selected or deselected. |
|
应用于该纸片的 ARIA 选定属性。 The ARIA selected applied to the chip. |
|
该纸片的头像 The chip avatar |
|
纸片列表是否可选 Whether the chip list is selectable |
|
Default color to fall back to if no value is set. |
|
Tabindex to which to fall back to if no value is set. |
|
该纸片的移除切换器。 The chip's remove toggler. |
|
该纸片的尾部图标。 The chip's trailing icon. |
方法
deselect | |
---|---|
取消选择该纸片。 Deselects the chip. |
focus | |
---|---|
允许通过编程把该纸片设为焦点。 Allows for programmatic focusing of the chip. |
remove | |
---|---|
允许以编程方式移除该纸片。当按下 DELETE 或 BACKSPACE 键时,会由 MatChipList 调用。 Allows for programmatic removal of the chip. Called by the MatChipList when the DELETE or BACKSPACE keys are pressed. 通知任何监听器这个删除请求。但不会从 DOM 中移除纸片。 Informs any listeners of the removal request. Does not remove the chip from the DOM. |
select | |
---|---|
选择该纸片。 Selects the chip. |
selectViaInteraction | |
---|---|
选择这个纸片并发出 selected 事件 Select this chip and emit selected event |
toggleSelected | |
---|---|
切换当前纸片的选定状态。 Toggles the current selected state of this chip. |
|
参数 Parameters |
|
isUserInput boolean = false
|
|
返回值 Returns |
|
boolean
|
|
MatChipRemove
应用正确的(click)支持,并为 https://material.io/icons/#ic_cancel 提供的 Material Design “cancel” 图标添加样式。
Applies proper (click) support and adds styling for use with the Material Design "cancel" icon available at https://material.io/icons/#ic_cancel.
示例:
Example:
`<mat-chip>
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>`
你可以使用自定义图标,但是可能需要改写 mat-chip-remove
的定位样式,这样才能让图标在纸片内正确居中。
You may use a custom icon, but you may need to override the mat-chip-remove
positioning
styles to properly center the icon within the chip.
MatChipInput
该指令用于把纸片特有的行为添加到 <mat-form-field>
里面的输入框元素中。可以放在 <mat-chip-list>
的内部或外部。
Directive that adds chip-specific behaviors to an input element inside <mat-form-field>
.
May be placed inside or outside of an <mat-chip-list>
.
属性
名称 | 描述 |
---|---|
@Input('matChipInputAddOnBlur')
|
当输入失焦时,是否会发出 chipEnd 事件。 Whether or not the chipEnd event will be emitted when the input is blurred. |
@Input('matChipInputFor')
|
注册纸片列表的输入框 Register input for chip list |
@Input()
|
输入框是否被禁用。 Whether the input is disabled. |
@Input()
|
该输入框的唯一 ID。 Unique id for the input. |
@Input()
|
输入框的占位符文本。 The input's placeholder text. |
@Input('matChipInputSeparatorKeyCodes')
|
会触发 chipEnd 事件的键盘代码列表。 The list of key codes that will trigger a chipEnd event. 默认为 Defaults to |
@Output('matChipInputTokenEnd')
|
当要添加纸片时会触发。 Emitted when a chip is to be added. |
|
输入框是否为空。 Whether the input is empty. |
|
控件是否有焦点。 Whether the control is focused. |
方法
focus | |
---|---|
让输入框获得焦点。 Focuses the input. |
|
参数 Parameters |
|
options? FocusOptions
|
|
类
MatChipListChange
纸片列表的值发生变化时发出的事件对象。
Change event object that is emitted when the chip list value has changed.
属性
名称 | 描述 |
---|---|
|
Chip list that emitted the event. |
|
Value of the chip list when the event was emitted. |
MatChipSelectionChange
MatChip 在选定或取消选定时会发出本事件对象。
Event object emitted by MatChip when selected or deselected.
属性
名称 | 描述 |
---|---|
|
Whether the selection change was a result of a user interaction. |
|
Whether the chip that emitted the event is selected. |
|
Reference to the chip that emitted the event. |
接口
MatChipEvent
表示单个 mat-chip
上触发的事件。
Represents an event fired on an individual mat-chip
.
属性
名称 | 描述 |
---|---|
|
触发该事件的纸片。 The chip the event was fired on. |
MatChipInputEvent
表示 matChipInput
上的输入事件。
Represents an input event on a matChipInput
.
属性
名称 | 描述 |
---|---|
|
触发该事件的原生 The native |
|
输入框的值。 The value of the input. |
MatChipsDefaultOptions
纸片模块的默认选项,可以改写它们。
Default options, for the chips module, that can be overridden.
属性
名称 | 描述 |
---|---|
|
会触发 chipEnd 事件的键盘代码列表。 The list of key codes that will trigger a chipEnd event. |
常量
MAT_CHIP_REMOVE
这个注入令牌可以用来引用 MatChipRemove
实例。它可以作为实际 MatChipRemove
类的备用令牌,直接使用实际类可能导致该类及其元数据无法被优化掉。
Injection token that can be used to reference instances of MatChipRemove
. It serves as
alternative token to the actual MatChipRemove
class which could cause unnecessary
retention of the class and its directive metadata.
const MAT_CHIP_REMOVE: InjectionToken<MatChipRemove>;
MAT_CHIP_AVATAR
这个注入令牌可以用来引用 MatChipAvatar
实例。它可以作为实际 MatChipAvatar
类的备用令牌,直接使用实际类可能导致该类及其元数据无法被优化掉。
Injection token that can be used to reference instances of MatChipAvatar
. It serves as
alternative token to the actual MatChipAvatar
class which could cause unnecessary
retention of the class and its directive metadata.
const MAT_CHIP_AVATAR: InjectionToken<MatChipAvatar>;
MAT_CHIP_TRAILING_ICON
这个注入令牌可以用来引用 MatChipTrailingIcon
实例。它可以作为实际 MatChipTrailingIcon
类的备用令牌,直接使用实际类可能导致该类及其元数据无法被优化掉。
Injection token that can be used to reference instances of MatChipTrailingIcon
. It serves as
alternative token to the actual MatChipTrailingIcon
class which could cause unnecessary
retention of the class and its directive metadata.
const MAT_CHIP_TRAILING_ICON: InjectionToken<MatChipTrailingIcon>;
MAT_CHIPS_DEFAULT_OPTIONS
注入令牌,用于改写纸片模块的默认选项。
Injection token to be used to override the default options for the chips module.
const MAT_CHIPS_DEFAULT_OPTIONS: InjectionToken<MatChipsDefaultOptions>;
Angular Material chips-testing API 参考文档
import {MatChipListHarness} from '@angular/material/chips/testing';
类
MatChipListHarness
在测试中与标准纸片列表进行交互的测试工具。
Harness for interacting with a standard chip list in tests.
方法
异步
getChips
|
|
---|---|
获取纸片列表中的纸片列表。 Gets the list of chips inside the chip list. |
|
参数 Parameters |
|
filter ChipHarnessFilters = {}
|
(可选项)用于过滤纸片。 Optionally filters which chips are included. |
返回值 Returns |
|
Promise<MatChipHarness[]>
|
|
异步
getInput
|
|
---|---|
获取纸片列表中的 Gets the |
|
参数 Parameters |
|
filter ChipInputHarnessFilters = {}
|
一个可选的过滤器,用于过滤纸片。。 Optionally filters which chip input is included. |
返回值 Returns |
|
Promise<MatChipInputHarness>
|
|
getOrientation | |
---|---|
返回值 Returns |
|
Promise<'horizontal' | 'vertical'>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
isDisabled | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isInvalid | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isMultiple | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isRequired | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
已弃用
异步
selectChips
|
|
---|---|
选定纸片列表中的纸片。 Selects a chip inside the chip list. |
|
参数 Parameters |
|
filter ChipHarnessFilters = {}
|
一个可选的过滤器,适用于子纸片。所有与过滤器匹配的纸片都会被选定。 An optional filter to apply to the child chips. All the chips matching the filter will be selected. |
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
MatChipHarness
extends
ComponentHarness
在测试中与标准可选 Angular Material 纸片的测试工具。
Harness for interacting with a standard selectable Angular Material chip in tests.
方法
异步
getRemoveButton
|
|
---|---|
获取一个纸片里面的移除按钮。 Gets the remove button inside of a chip. |
|
参数 Parameters |
|
filter ChipRemoveHarnessFilters = {}
|
可选择过滤哪些纸片。 Optionally filters which chips are included. |
返回值 Returns |
|
Promise<MatChipRemoveHarness>
|
|
异步
getText
|
|
---|---|
获取该纸片的文本。 Gets the text of the chip. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
异步
isDisabled
|
|
---|---|
纸片是否被禁用了。 Whether the chip is disabled. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
remove
|
|
---|---|
移除指定的纸片。只有它可移除时才适用。 Removes the given chip. Only applies if it's removable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
已弃用
异步
deselect
|
|
---|---|
取消选定指定的纸片。仅当它可选时才适用。 Deselects the given chip. Only applies if it's selectable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
已弃用
异步
isSelected
|
|
---|---|
纸片是否被选定。 Whether the chip is selected. |
|
返回值 Returns |
|
Promise<boolean>
|
|
已弃用
异步
select
|
|
---|---|
选定指定的纸片。仅当它可选时才适用。 Selects the given chip. Only applies if it's selectable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
已弃用
异步
toggle
|
|
---|---|
切换指定纸片的选定状态。仅当它可选时才适用。 Toggles the selected state of the given chip. Only applies if it's selectable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
MatChipInputHarness
extends
ComponentHarness
在测试中用来与标准 Material 纸片组件交互的测试工具。
Harness for interacting with a standard Material chip inputs in tests.
方法
异步
blur
|
|
---|---|
失焦输入框并返回一个 Promise,表明该动作什么时候完成。 Blurs the input and returns a promise that indicates when the action is complete. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
focus
|
|
---|---|
聚焦输入框并返回一个 Promise,表明该动作何时完成。 Focuses the input and returns a promise that indicates when the action is complete. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
getPlaceholder
|
|
---|---|
获取输入框的占位符。 Gets the placeholder of the input. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getValue
|
|
---|---|
获取输入框的值。 Gets the value of the input. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
异步
isDisabled
|
|
---|---|
输入框是否被禁用。 Whether the input is disabled. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isFocused
|
|
---|---|
输入框是否拥有焦点。 Whether the input is focused. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isRequired
|
|
---|---|
输入框是否为必需的。 Whether the input is required. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
sendSeparatorKey
|
|
---|---|
向输入框元素发送一个纸片分隔键。 Sends a chip separator key to the input element. |
|
参数 Parameters |
|
key string | TestKey
|
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
setValue
|
|
---|---|
设置输入框的值。该值将通过模拟与指定值对应的按键进行设置。 Sets the value of the input. The value will be set by simulating keypresses that correspond to the given value. |
|
参数 Parameters |
|
newValue string
|
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
MatChipRemoveHarness
extends
ComponentHarness
在测试过程中与标准 Material 纸片移除按钮交互的工具。
Harness for interacting with a standard Material chip remove button in tests.
方法
异步
click
|
|
---|---|
点击“删除”按钮。 Clicks the remove button. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
MatChipOptionHarness
extends
MatChipHarness
方法
异步
deselect
|
|
---|---|
取消选择指定的纸片。仅当它可以选择时才适用。 Deselects the given chip. Only applies if it's selectable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
getRemoveButton
|
|
---|---|
获取一个纸片里面的移除按钮。 Gets the remove button inside of a chip. |
|
参数 Parameters |
|
filter ChipRemoveHarnessFilters = {}
|
可选择过滤哪些纸片。 Optionally filters which chips are included. |
返回值 Returns |
|
Promise<MatChipRemoveHarness>
|
|
异步
getText
|
|
---|---|
获取该纸片的文本。 Gets the text of the chip. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
异步
isDisabled
|
|
---|---|
纸片是否被禁用了。 Whether the chip is disabled. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isSelected
|
|
---|---|
纸片是否被选定。 Whether the chip is selected. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
remove
|
|
---|---|
移除指定的纸片。只有它可移除时才适用。 Removes the given chip. Only applies if it's removable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
select
|
|
---|---|
选择指定的纸片。仅当它可以选择时才适用。 Selects the given chip. Only applies if it's selectable. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
toggle
|
|
---|---|
切换指定纸片的选定状态。 Toggles the selected state of the given chip. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
MatChipListboxHarness
在测试中用来与标准可选纸片列表进行交互的测试工具。
Harness for interacting with a standard selectable chip list in tests.
方法
异步
getChips
|
|
---|---|
获取纸片列表中的各个纸片。 Gets the list of chips inside the chip list. |
|
参数 Parameters |
|
filter ChipOptionHarnessFilters = {}
|
可选择过滤哪些纸片。 Optionally filters which chips are included. |
返回值 Returns |
|
Promise<MatChipOptionHarness[]>
|
|
getOrientation | |
---|---|
返回值 Returns |
|
Promise<'horizontal' | 'vertical'>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
isDisabled | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isInvalid | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isMultiple | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
isRequired | |
---|---|
返回值 Returns |
|
Promise<boolean>
|
|
异步
selectChips
|
|
---|---|
选择纸片列表中的纸片。 Selects a chip inside the chip list. |
|
参数 Parameters |
|
filter ChipOptionHarnessFilters = {}
|
一个可选的过滤器,适用于子纸片。所有与过滤器匹配的纸片都会被选定。 An optional filter to apply to the child chips. All the chips matching the filter will be selected. |
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
接口
ChipHarnessFilters
一组可以用来过滤纸片实例列表的标准。
A set of criteria that can be used to filter a list of chip instances.
属性
名称 | 描述 |
---|---|
|
只查找文本与指定值匹配的实例。 Only find instances whose text matches the given value. |
已弃用
|
只查找选定状态与指定值匹配的纸片实例。 Only find chip instances whose selected state matches the given value. |
ChipOptionHarnessFilters
一组可以用来过滤可选纸片实例列表的标准。
A set of criteria that can be used to filter a list of selectable chip instances.
属性
名称 | 描述 |
---|---|
|
只查找选定状态与指定值匹配的纸片实例。 Only find chip instances whose selected state matches the given value. |
ChipListHarnessFilters
一组可以用来过滤纸片列表实例的标准。
A set of criteria that can be used to filter chip list instances.
ChipListboxHarnessFilters
一组可用于过滤可选纸片列表实例的准则。
A set of criteria that can be used to filter selectable chip list instances.
ChipInputHarnessFilters
一组标准,可以用来过滤 MatChipListInputHarness
实例列表。
A set of criteria that can be used to filter a list of MatChipListInputHarness
instances.
属性
名称 | 描述 |
---|---|
|
根据输入的占位符文本进行过滤。 Filters based on the placeholder text of the input. |
|
根据输入值过滤。 Filters based on the value of the input. |
ChipRemoveHarnessFilters
一组可以用来过滤 MatChipRemoveHarness
实例列表的条件。
A set of criteria that can be used to filter a list of MatChipRemoveHarness
instances.