Angular Material input API 参考文档
import {MatInputModule} from '@angular/material/input';
指令
MatTextareaAutosize
extends
CdkTextareaAutosize
用于自动调整 textarea 大小以适应其内容的指令。
Directive to automatically resize a textarea to fit its content.
属性
名称 | 描述 |
---|---|
@Input('cdkTextareaAutosize')
|
是否启用了自动调整大小的功能 Whether autosizing is enabled or not |
@Input('mat-autosize')
|
|
@Input()
|
|
@Input()
|
|
@Input()
|
|
@Input('cdkAutosizeMaxRows')
|
textarea 中的最大行数。 Maximum amount of rows in the textarea. |
@Input('cdkAutosizeMinRows')
|
textarea 中的最小行数。 Minimum amount of rows in the textarea. |
@Input()
|
方法
reset | |
---|---|
把 textarea 重置为原始大小 Resets the textarea to its original size |
resizeToFitContent | |
---|---|
调整 textarea 的大小以适应它的内容。 Resize the textarea to fit its content. 是否强行重新计算高度。默认情况下,只有当自上一次调用后的值发生变化时,才会重新计算高度。 @param force Whether to force a height recalculation. By default the height will be recalculated only if the value changed since the last call. |
|
参数 Parameters |
|
force boolean = false
|
|
MatInput
允许原生输入工作于 MatFormField
中的指令。
Directive that allows a native input to work inside a MatFormField
.
属性
名称 | 描述 |
---|---|
@Input()
|
用于控制何时显示错误信息的对象。 An object used to control when error messages are shown. |
@Input()
|
该元素是否只读。 Whether the element is readonly. |
@Input()
|
该元素的输入框类型。 Input type of the element. |
|
方法
focus | |
---|---|
让此输入框获得焦点。 Focuses the input. |
|
参数 Parameters |
|
options? FocusOptions
|
|
updateErrorState |
---|
常量
MAT_INPUT_VALUE_ACCESSOR
这个令牌用于注入那些应该把值设置进 MatInput
的对象。如果没有提供,就会使用原生 HTMLInputElement
。像 MatDatepickerInput
这样的指令可以为此令牌提供自己的能力,以便让 MatInput
委托对它们进行获取和设置。
This token is used to inject the object whose value should be set into MatInput
. If none is
provided, the native HTMLInputElement
is used. Directives like MatDatepickerInput
can provide
themselves for this token, in order to make MatInput
delegate the getting and setting of the
value to them.
const MAT_INPUT_VALUE_ACCESSOR: InjectionToken<{ value: any; }>;
Angular Material input-testing API 参考文档
import {MatInputHarness} from '@angular/material/input/testing';
类
MatInputHarness
extends
MatFormFieldControlHarness
在测试中与标准 Material 输入框进行交互的测试工具。
Harness for interacting with a standard Material inputs in tests.
方法
异步
blur
|
|
---|---|
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
|
|
---|---|
Focuses the input and returns a promise that indicates when the action is complete. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
getId
|
|
---|---|
Gets the id of the input. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getName
|
|
---|---|
Gets the name of the input. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getPlaceholder
|
|
---|---|
获取输入框的占位符。 Gets the placeholder of the input. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getType
|
|
---|---|
Gets the type of the input. Returns "textarea" if the input is a textarea. |
|
返回值 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>
|
|
异步
isReadonly
|
|
---|---|
Whether the input is readonly. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isRequired
|
|
---|---|
输入框是否为必需的。 Whether the input is required. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
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. |
MatNativeSelectHarness
extends
MatFormFieldControlHarness
Harness for interacting with a native select
in tests.
方法
异步
blur
|
|
---|---|
Blurs the select and returns a void promise that indicates when the action is complete. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
focus
|
|
---|---|
Focuses the select and returns a void promise that indicates when the action is complete. |
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
异步
getId
|
|
---|---|
Gets the id of the select. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getName
|
|
---|---|
Gets the name of the select. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
getOptions
|
|
---|---|
Gets the options inside the select panel. |
|
参数 Parameters |
|
filter NativeOptionHarnessFilters = {}
|
|
返回值 Returns |
|
Promise<MatNativeOptionHarness[]>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
异步
isDisabled
|
|
---|---|
Gets a boolean promise indicating if the select is disabled. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isFocused
|
|
---|---|
此选择器是否拥有焦点。 Whether the select is focused. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isMultiple
|
|
---|---|
Gets a boolean promise indicating if the select is in multi-selection mode. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isRequired
|
|
---|---|
Gets a boolean promise indicating if the select is required. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
selectOptions
|
|
---|---|
Selects the options that match the passed-in filter. If the select is in multi-selection mode all options will be clicked, otherwise the harness will pick the first matching option. |
|
参数 Parameters |
|
filter NativeOptionHarnessFilters = {}
|
|
返回值 Returns |
|
Promise<void>
|
Promise that resolves when the action completes. |
MatNativeOptionHarness
extends
ComponentHarness
Harness for interacting with a native option
in tests.
方法
异步
getIndex
|
|
---|---|
Index of the option within the native |
|
返回值 Returns |
|
Promise<number>
|
|
异步
getText
|
|
---|---|
Gets the option's label text. |
|
返回值 Returns |
|
Promise<string>
|
|
异步
host
|
|
---|---|
获取一个代表该组件宿主元素的 Gets a |
|
返回值 Returns |
|
Promise<TestElement>
|
|
异步
isDisabled
|
|
---|---|
Gets whether the option is disabled. |
|
返回值 Returns |
|
Promise<boolean>
|
|
异步
isSelected
|
|
---|---|
Gets whether the option is selected. |
|
返回值 Returns |
|
Promise<boolean>
|
|
接口
InputHarnessFilters
A set of criteria that can be used to filter a list of MatInputHarness
instances.
属性
名称 | 描述 |
---|---|
|
根据输入的占位符文本进行过滤。 Filters based on the placeholder text of the input. |
|
根据输入值过滤。 Filters based on the value of the input. |
NativeSelectHarnessFilters
A set of criteria that can be used to filter a list of MatNativeSelectHarness
instances.
NativeOptionHarnessFilters
A set of criteria that can be used to filter a list of MatNativeOptionHarness
instances.
属性
名称 | 描述 |
---|---|
|
|
|
|
|