连字符的属性值导致AngularJs验证中断 [英] Hyphen in attribute value causing AngularJs validation break
问题描述
我刚注意到,如果我在表单名称属性或输入的名称属性中使用连字符,AngularJS验证无效。
这不起作用如果我尝试验证字段
< form name =signup-form>
< / form>
以下作品完美无缺
< form name =signupform>
< / form>
有人可以解释为什么AngularJs在第一种情况下不起作用吗?如果我们要 - 工作,我们该怎么做?解决方案
问题是,你放的名字到名称
属性也是表单发布在范围
下的JavaScript属性的名称(例如for在你的控制器内使用它)。不过,包含连字符的属性名称无效。我很确定没有办法绕过它。
I just noticed that if i have a hyphen in the form name attribute or the input's name attribute, AngularJS validations don't work.
This doesn't work if i try to validate the fields
<form name="signup-form">
</form>
The below works perfectly
<form name="signupform">
</form>
Can someone please explain why AngularJs doesn't work in the first case? And if we were to have "-" work, how can we do that?
The problem is that the name you put into the name
attribute is also the name for the JavaScript property under which the form is published on the scope
(e.g. for using it inside your controller). An attribute name containing a hyphen is not valid JavaScript though. I'm pretty sure there is no way around it.
这篇关于连字符的属性值导致AngularJs验证中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!