连字符的属性值导致AngularJs验证中断 [英] Hyphen in attribute value causing AngularJs validation break

查看:81
本文介绍了连字符的属性值导致AngularJs验证中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚注意到,如果我在表单名称属性或输入的名称属性中使用连字符,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屋!

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