问题标签 [mat-error]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
185 浏览

angular - Mat 错误未显示自定义验证器的错误,但模板显示错误

app.component.html

app.component.ts

...

我正在尝试自定义验证器。html 表单 json 管道显示输出,但 mat 错误未显示输出。

0 投票
0 回答
86 浏览

angular - mat-error 没有出现在 ControlValueAccessor 中

我有一个app-input使用的自定义组件,mat-form-fieldmat-error没有出现错误。

我是否NgControlformfield正确的方式分配?

零件

模板

0 投票
1 回答
68 浏览

angular - mat 错误在单击按钮时不显示错误。角度 7

我在 mat 错误中显示错误消息时遇到问题。以下是html代码。

HTML

当字段为空时显示此错误,但单击添加媒体按钮时不会显示mediaUpinNotExist的错误。

TS代码

我已经使用了一种解决方案——markAsTouched。formcontrol 在 TS 文件中被 markAsTouched 但不显示消息。

当我再次单击输入框时,将显示错误消息。单击添加媒体按钮后,数据也未显示在表格中。

表格请看截图。当我再次单击输入框时,数据将显示在表格中。输入框和表格显示数据

编辑 :

我还使用了以下功能:

这个匹配器我在垫子输入中使用过。

0 投票
1 回答
145 浏览

angular - 成功验证后,mat-input 仍然无效 - Angular 12

组件代码-

html代码-

匹配当前密码的验证工作完美,并根据条件显示错误消息。但此后其输入字段仍然无效

我也尝试过验证其余的输入字段。但是currentPassword仍然无效,这会导致整个表单仍然无效

为什么会发生这种情况以及如何解决?有谁有想法吗?

0 投票
1 回答
141 浏览

angular-material - Angular 11 Custom ISBN Validator Reactive Forms

I'm doing a custom validation for an ISBN number, I already have the function that checks the number and works perfect giving me the response by console, but I need to do the custom validator to get the error in the view with the form control and in this step this error is showing in console when I write an ISBN number, It's like it checks the errors but it doesn't know when its right and it should take the null response as a right ISBN number, at least thats what I saw in some examples.

This is my typescript,

In my HTML I have some inputs that are included in the form:

0 投票
1 回答
37 浏览

angular - 角度 materror 检查下拉 ngmodel 对象有效

再会,

通常,我会将下拉值设置为字符串,例如:

下拉列表中设置rReloadType.key为 的值在哪里,如果用户单击下拉列表,但未选择任何值,则将显示在下拉列表下方。stringreloadTypeObjStr"reloadTo is required"

我希望有一个下拉列表,将值设置为对象而不是字符串,例如:

where是下拉列表rReloadType中的对象(而不是),并设置为,这是一个对象。此时,如果用户没有从该下拉列表中选择任何值,则不会显示,此时 mat-error 不起作用。stringreloadTypeObjreloadTo is required

我想请教一下,有什么我可以做的吗?或者角度不支持这个?我必须使用字符串值而不是对象值进行下拉?

0 投票
1 回答
27 浏览

angular - 无效时的mat-form-field轮廓悬停效果

我正在尝试更改背景的颜色,即鼠标悬停时勾勒出的垫子表单字段的颜色。

上面的代码运行良好,当表单控件有效但是当它无效时,我尝试了:

这会永久改变颜色。不仅当我有鼠标悬停时。请帮忙。谢谢,大卫