简体   繁体   中英

How to access dynamically added DOM element in Angular?

I am implementing the required constraint through $error . I want to access The input element inside the from. ie {{frm.item.qid.$error.required}}

But since the form Object contains attribute q1 (value of item.qid ), frm.item returns null .

So How can I access, lets say frm.q1 (values for item.qid are : q1,q2,q3, etc.) ?

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,你应该看看里面是什么。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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