问题标签 [ng-messages]

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 投票
2 回答
750 浏览

javascript - AngularJS 中的 ngMessages 验证不会清除 CSS 中的错误消息

你知道为什么即使没有错误并且验证通过,我仍然会出现红色下划线错误吗?

在此处输入图像描述

我有自己的指令来匹配密码,并且我正在使用 Angular 材料。

这里的工作代码:::::::::::::::

http://codepen.io/anon/pen/gPrMRM

http://codepen.io/anon/pen/gPrMRM

Angular 应用程序和 js:

HTML:

这里的工作代码:::::::::::::::

http://codepen.io/anon/pen/gPrMRM

http://codepen.io/anon/pen/gPrMRM

0 投票
1 回答
457 浏览

angularjs - 是否可以使用 ngMessages 制作可重用的表单组件?

这是html代码,我想制作一个指令

但我不知道如何为任何组件传递变量,即 formname.inputname.$error

更新:到目前为止的进展:

模板 :

指令:

指令模板:

0 投票
2 回答
2070 浏览

angularjs - Angular ng 消息、错误、警告和表单有效性

ng-messages 是否有角度(1.4+)方式来显示警告和错误,不同之处在于警告不会使表单无效,但错误会导致即使有警告用户也可以保存表单?到处搜索,似乎找不到任何关于此的内容,尽管我认为它应该是系统 o_O 的一个明显部分

0 投票
1 回答
252 浏览

javascript - 为什么 ngMessages 警报只出现一次?

为什么 ngMessages 警报只出现一次?当我从引导选项中使用 (data-dismiss="alert" class="close") 时,警报被隐藏,但它再也不会出现。

代码笔: http ://codepen.io/mescal/pen/PZpWjd?editors=101

谢谢!

0 投票
0 回答
107 浏览

angularjs - 在父控制器中带有自定义验证器的 ngMessages

我试图弄清楚如何将自定义验证器与可以访问父范围的 ngMessages 连接起来。我有一个地址输入字段,onBlur我想对地址进行地理定位并更新地图上标记的位置(通过在控制器上设置两个变量this)。

自定义验证器示例使用指令(我已经按照这些指令作为基本示例)但无法从它们移动到地理位置,因为我在ES6、ControllerAs、 ...

感谢有关接线的建议。

这是我在第二种情况下到达的地方

这是我需要能够与控制器范围一起使用的控制器功能

0 投票
1 回答
3826 浏览

angularjs - ng-messages not displaying validation errors properly

I have made a basic form using angular material and would like to have specific error messages pop up when an input is invalid. I tried to model it after the input example on the official website, which uses the ng-messages directive to display the validation errors. For whatever reason, error messages only seem to get shown when the validation state transitions from valid to invalid.

For example, there is an input like <input type="email" required> with an <ng-message when="email"> that says "Please enter a valid email." Writing an invalid email and then tabbing away to the next value triggers validation, the invalid style gets applied to the input and the message gets shown. If instead I immediately proceed to the next input without entering anything the element also gets the invalid style applied (because of the required attribute) and no message appears as expected (I did not include one for required). But if I focus the input again and write an invalid email, the message does not show up (even if I move focus away and back). The input element still has the invalid style applied to it however. The message only shows up again when I write an invalid email (causing the invalid style to be removed from the element) and then delete it to make it invalid again.

Here is an example CodePen which shows his behavior, and displays the values of the form attributes. The markup is:

The javascript is nothing but

You can see the inputs are being correctly validated, but it looks like the message elements aren't having the right styles applied to them (opacity: 1) when they should.

0 投票
2 回答
2924 浏览

javascript - 根据多个条件显示带有 ng-messages 的验证消息

我使用角度 ng-messages 来显示验证消息

考虑以下代码:

我只想在所有其他验证都通过并且验证在 onlyAfterAllOtherPassedValidation 上失败时才显示最后一条验证消息。而且我不知道是否有可能将复杂条件传递给 ng-message 只要我仍然可以使用 ng-messages,欢迎任何建议和解决方法

0 投票
2 回答
907 浏览

angularjs - 如何在 ng-messages 指令中插入表达式?

假设我有一个表单名称"signupForm"。当我在按钮上使用 ng-disabled 指令时(禁用表单以防其无效),我使用 ng-disabled="{{formName}}.$invalid">(formName 包含值signupForm

当我检查浏览器中的按钮时,上述指令的计算结果为ng-disabled="signupForm.$invalid">. 太棒了。问题是当我尝试在 ng-messages 指令中使用相同的表达式时,例如:ng-messages ="{{formName}}.$error">表达式没有被插值。因此,如果我在 div 上使用该指令并在浏览器中检查它,我会看到它: <div ng-messages="{{formName}}.$error"></div>而我希望它显示为<div ng-messages="signupForm.$error"></div>. 但这不会发生。

那么如何使 ng-messages 指令插入表达式并正确显示呢?我已经用 AngularJS 1.4.7 和 1.5.0-rc.1 测试了这个问题,并且两者都存在这个问题。任何帮助表示赞赏。谢谢你。

0 投票
2 回答
8364 浏览

angularjs - 如何使用 ng-messages 显示 Checkbox set 和 Radio set 的错误消息?

我一直在尝试验证 Checkbox set 和 Radio set 并使用 ng-messages 指令显示错误消息,但它没有按预期工作。ng-messages 根本不显示错误消息。我正在使用 html 文件填充错误消息。在错误解决之前,我的表单中的提交按钮将被禁用。

在以下情况下,如何显示复选框集和单选集的错误消息:

  1. Radio set 中没有选择一个选项?

  2. Checkbox set 中至少有一个选项没有被选中?

  3. 缩放 Checkbox 集的检查,以便我们可以检查至少 2 个或更多被选中,等等?

这是我的表格:

消息.html

控制器.js

付款复选框集:

0 投票
1 回答
1023 浏览

javascript - 单击提交按钮后如何使用 ng 消息检查表单验证?

创建指令以检查验证并且工作正常,但即使在表单完全填写后,提交按钮也无法正常工作。 注意:提交按钮(下一步)在我添加指令之前工作正常,我正在使用角度材料和 ng-messages 工作正常但仅当您尝试填写这些必填字段但如果我没有触摸或错过字段时不会显示任何错误消息,因此我添加了 validForm 指令以在单击下一步(提交)时验证表单,并且在添加指令后,单击下一步按钮时会显示错误消息,但不会将您带到下一步页面。
指令代码:

});

控制器代码:

html: