简体   繁体   English

如何访问Angular中动态添加的DOM元素?

[英]How to access dynamically added DOM element in Angular?

I am implementing the required constraint through $error . 我正在通过$error实现所需的约束。 I want to access The input element inside the from. 我要访问from中的输入元素。 ie {{frm.item.qid.$error.required}} {{frm.item.qid.$error.required}}

But since the form Object contains attribute q1 (value of item.qid ), frm.item returns null . 但是由于表单对象包含属性q1item.qid值),因此frm.item返回null

So How can I access, lets say frm.q1 (values for item.qid are : q1,q2,q3, etc.) ? 那么,如何可以访问,可以说frm.q1 (值item.qid是:Q1,Q2,Q3等)?

Here's the code: 这是代码:

<li ng-repeat = "item in questions">
  <input name = {{item.qid}} type = "radio" ng-value = "item.option1" ng-model="item.selectedOption" required/>
  <label ng-bind = "item.option1"></label>
  <input name = {{item.qid}} type = "radio" ng-value = "item.option2" ng-model="item.selectedOption"/>
  <label ng-bind = "item.option2"></label>
  <input name = {{item.qid}} type = "radio" ng-value = "item.option3" ng-model="item.selectedOption"/>
  <label ng-bind = "item.option3"></label>
  <input name = {{item.qid}} type = "radio" ng-value = "item.option4" ng-model="item.selectedOption"/>
  <label ng-bind = "item.option4"></label>
  <label ng-show="">This is manadatory</label>
</li>

如果打印{{FRM}}后您的ul li在DOM,你应该看看里面是什么。

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

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