angularjs形式不能引用输入控制时输入的名字是阵列 [英] angularjs form can not refer to input control when input name is array

查看:102
本文介绍了angularjs形式不能引用输入控制时输入的名字是阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试用angularjs表单验证的时候遇到问题

I encounter a problem when testing form validation with angularjs

根据 angularjs形式指南

这具有ngModel指令的输入控制持有NgModelController的一个实例。这种控制的实例可发布为使用输入控件的名称属性的窗体实例的属性。

an input control that has the ngModel directive holds an instance of NgModelController. Such a control instance can be published as a property of the form instance using the name attribute on the input control.

我创建的测试code。在 plunker ,这一切工作正常,直到我从

I created test code at plunker, it all works fine untill I change the input name from

<input type="number" name="age" ng-model="user.age" max="100" required>

<p>{{form1.age.$error}}</p>

<input type="number" name="user[age]" ng-model="user.age" max="100" required>

<p>{{form1.user[age].$error}}</p>

这是否意味着角无法识别表单输入数组语法?

对于我的问题是我要保持正常的表单提交流量和只使用角度为表单验证,所以我需要保持的形式输入作为数组与后端表单处理工作。

Does this mean angular can not recognize array syntax in form input?

The problem for me is I want to keep the normal form submission flow and only use angular for form validation, so I need to keep form input as array to work with the backend form handling

推荐答案

它无关,与棱角分明。这是一个语法JS错误。

It has nothing to do with Angular. It is a syntactic JS error.

如果你想引用一个命名属性用户[年龄] ,你应该这样做是这样的:

If you want to reference a property named user[age], you should do it like this:

form1['user[age]'].$error

<分> form1.user [年龄] 是PTED为不当间$ P $(form1.user)[年龄]

form1.user[age] is incorrectly interpreted as (form1.user)[age]

这篇关于angularjs形式不能引用输入控制时输入的名字是阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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