首页 > 解决方案 > 离子输入无法绑定到“errorStateMatcher”

问题描述

我正在尝试将我的一些工作角度代码复制到 Ionic 项目中,但出现以下错误。我不能在 Ionic 中使用 ErrorStateMatcher 吗?有关如何解决错误的任何建议?

ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'errorStateMatcher' since it isn't a known property of 'ion-input'.
1. If 'ion-input' is an Angular component and it has 'errorStateMatcher' input, then verify that it is part of this module.
2. If 'ion-input' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("="password" [(ngModel)]="passwordConfirm" name="passwordConfirm" formControlName="confirmPassword"  [ERROR ->][errorStateMatcher]="matcher"></ion-input>
            <div *ngFor="let validation of memberValidatio"): ng:///RegisterPageModule/RegisterPage.html@65:125



 <ion-input type="password" [(ngModel)]="passwordConfirm" name="passwordConfirm" formControlName="confirmPassword"  [errorStateMatcher]="matcher"></ion-input>

标签: angularionic-framework

解决方案


ErrorStateMatcher 在@angular/material 库中定义。确保添加库并导入必要的模块。

mat-form-field 允许您将错误消息与 matInput 相关联。默认情况下,当控件无效并且用户已与(触摸)元素交互或已提交父表单时,将显示这些错误消息。如果您希望覆盖此行为(例如,在无效控件脏或父表单组无效时立即显示错误),您可以使用 matInput 的 errorStateMatcher 属性

有关更多信息,请参阅:Ionic 4 中的 Angular Material 入门


推荐阅读