动态ID NG-重复 [英] dynamic id ng-repeat

查看:127
本文介绍了动态ID NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个动态的ID设置为我的NG-重复内我股利。让我告诉一个例子。

I am trying to set a dynamic id to my div within my ng-repeat. Let me show an example.

<div id="$index" ng-repeat="repeat in results.myJsonResults">
    <div id="$index" ng-click="saveID($index)" ng-repeat="subRepeat in results.myJsonResults.subresults">
</div>

我的问题是,当我点击我的孩子的div,我想我的父母ID名称,但看起来像角不正确设置ID到div。是否有可能在这个概念设定一个动态的ID?

My problem is, when I click on my child div, I want to get my parent id name, but looks like angular doesn't set the ID properly to the div. Is it possible to set a dynamic ID in this concept?

PS:我试过了,在过去,创造我控制器上的计数器法,并设置一个索引,但事实证明,只有角度认识到这一ID的最后一个值,而不是

PS: I tried, in the past, create a counter method on my controller and set an index, but it turns out that angular only recognizes the last value of this ID instead.

推荐答案

要回答你的问题,试试这个:

To answer your question, try this:

<div id="{{$index}}" ...>

虽然上面应该工作,这可能是不是你想要的真的是(!)。请注意,这是相当罕见的与AngularJS操纵参照那些ID元素。

While the above should work, this might be not what you want really (!). Please note that this is rather rare with AngularJS to manipulate elements by referring those by id.

您应该专注于自己的模型,声明描述UI,让AngularJS完成剩下的没有手动做低层次的DOM操作。

You should focus on your model, declarative describe UI and let AngularJS do the rest without doing low-level DOM manipulations "by hand".

这篇关于动态ID NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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