如何在不输入任何字段的情况下触发角度解析器 [英] how to trigger angular parsers without inputing anything in the field

查看:21
本文介绍了如何在不输入任何字段的情况下触发角度解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如主题所述,我如何触发在 a 内发生的动作

As the subject states, how do I trigger the actions to take place inside a

modelController.$parsers(...) 

没有用户输入......我能想到的唯一方法是将它们包装在一个函数中并调用它,但是有没有更好的方法来触发

without user input... the only way I can think of is wrapping them inside a function and call it, but is there a better way to trigger

**//pseudo
$(modelController).trigger('just got dirty');**

我需要它的原因是触发输入字段以在提交页面上验证自身.

the reason I would need this is to trigger the input field to validate itself on submitting page.

推荐答案

我找到了解决这个问题的方法 - 只需使用模型值调用解析器:

I have found a way to solve this - just call the parsers with the model value:

angular.forEach(ngModel.$parsers, function (parser) {
    parser(ngModel.$viewValue);
});

就是这么简单,而且似乎是最正确的解决方案.

It`s so simple, and it seems to be the most correct solution.

这篇关于如何在不输入任何字段的情况下触发角度解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆