Angular 错误消息使用时屏幕上非常短 angular-ui ui-date datepicker

我遇到了一个问题 ng-message 闪烁错误消息 'required', 尽管在输入字段中存在输入。 发生了什么是很快闪烁错误消息: "此字段是必需的 /所有大写字母都可以更轻松地看到它 FLASH BY!/" 在屏幕上立即消失之前。 对不起标题字母,但我希望消息在消失之前更容易看到。

这里
https://plnkr.co/edit/jPAALWTt ... eview
. 请输入任何输入,然后单击其他位置,以便输入字段失去焦点。

注意,因为红色错误消息是 flash 很短的时间,然后消失

. 如果您没有注意到消息 flash 快速,您必须重新启动页面以查看其如何再次发生。

为什么这发生了? 我相信它是一个以某种方式与之相关联 ui-date, 因为我没有重现这个问题 ui-date.

这是代码的片段:


<form name="reportform" ng-submit="process_form//" novalidate="">
<input name="startdate" ng-model="startdatevalue" placeholder="Enter a start date" required="" ui-date=""/>
<ng-messages for="reportform.startdate.$error" ng-if="reportform.startdate.$touched">
<ng-message class="error-message" when="required">
THIS FIELD IS REQUIRED /ALL IN CAPS TO MAKE IT EASIER TO SEE IT FLASH BY!/
</ng-message>
</ng-messages>
<button ng-disabled="reportform.$invalid" type="submit">
Submit Query
</button>
</form>


谢谢您的帮助。
已邀请:

董宝中

赞同来自:

嗯,它可能有或没有与显示特定错误消息的关系,并且只有在使用模板时才显示出解决方案。 然而,尝试一些事情,我遇到了:


ng-cloak


从文档中:

指示 ngCloak 用于防止介绍模板 Angular html 浏览器在原始 /不受控制的/ 应用程序下载期间的表单。 使用此指令避免由模板显示引起的不需要的闪烁效果 html.

我把它添加到我的每一个 ngMessages Divov,眨眼的误区一直消失,这是有道理的。

裸奔

赞同来自:

尝试:


<ng-messages for="reportform.startdate.$error" ng-if="reportform.startdate.$touched &amp;&amp; reportform.startdate.$modelValue">
<ng-message class="error-message" when="required">
THIS FIELD IS REQUIRED /ALL IN CAPS TO MAKE IT EASIER TO SEE IT FLASH BY!/
</ng-message>
</ng-messages>


只需检查一下 modelValue 不是 null, 在删除错误之前。

我建议您在开发期间也检查模型中的值:


<pre>reportform.startdate.$error = {{reportform.startdate | json }}</pre>

詹大官人

赞同来自:

只是嗅到一点。 还要记住
https://coderoad.ru/17606936/
, 思考什么。


<form name="reportform" ng-submit="process_form//" novalidate="">
<input name="startdate" ng-model="startdatevalue" placeholder="Enter a start date" required="" ui-date=""/>
<ng-messages for="reportform.startdate.$error">
<ng-message class="error-message" when="required">
THIS FIELD IS REQUIRED /ALL IN CAPS TO MAKE IT EASIER TO SEE IT FLASH BY!/
</ng-message>
</ng-messages>
</form>


让我们看看它是否会纠正它,尽管我还没有检查过。

江南孤鹜

赞同来自:

会发生什么
$touched

在收集器中的日期输入鼠标光标时更新,但在您将光标提升之前,模型不会更新。 如果您点击日期并按下鼠标按钮,则这很明显。

一 /承认,黑客/ 绕过此问题使用参数的方法 ui-date, 检查日期选择是否已关闭,并在您的中使用它
ng-messages


ng-if

.


... ui-date="dateOptions" ng-model="startdatevalue" required>

<ng-messages for="reportform.startdate.$error" ng-if="reportform.startdate.$touched &amp;&amp; selectionComplete">


使用控制器中的以下内容


$scope.dateOptions = {
onClose: function// {
$scope.$apply/function//{
$scope.selectionComplete = true;
}/
}
}


更新 plnkr-
https://plnkr.co/edit/vgfI8lTn ... eview
快点 Github 页面 /
https://github.com/angular-ui/ui-date
/ 推荐用户界面引导日组件作为替代方案。
</ng-messages>

要回复问题请先登录注册