简体   繁体   English

角形式-如何用动态名称注册输入?

[英]Angular Forms - How to register inputs with dynamic names?

JSFiddle: http://jsfiddle.net/L8m7ptm7/ JSFiddle: http : //jsfiddle.net/L8m7ptm7/

I have an array of objects that represent questions I'd like to include within an Angular form: 我有一个对象数组,这些对象代表我想在Angular表单中包含的问题:

$scope.questions = [ { 'name': 'question1', 'label': 'Question 1', 'value': null }, { 'name': 'question2', 'label': 'Question 2', 'value': null } ];

The questions are rendered correctly within the DOM - with name attributes of question1 and question2 , as desired. 该问题是在DOM中正确呈现-与name的属性question1question2 ,根据需要。

The trouble arises when attempting to read these field's values out of the myForm object. 尝试从myForm对象中读取这些字段的值时会出现myForm Run the fiddle, and you'll see what happens. 运行小提琴,您将看到发生了什么。 Instead of the form containing keys for question1 and question2 , it contains a single key - {{question.name}} . 它不包含包含question1question2键的形式,而是包含单个键- {{question.name}}

Is it possible to have these fields register with the form object using the desired (rendered) names? 是否可以使这些字段使用所需的(呈现的)名称向表单对象注册?

在此处输入图片说明

I was at Angular 1.2. 我当时在Angular 1.2。 Upgrading to Angular 1.3.6 results in the desired behavior. 升级到Angular 1.3.6可获得所需的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM