【发布时间】:2015-06-04 16:03:18
【问题描述】:
.div(ng-repeat='item in items')
button(id='ID{{$index}}') No Hi
button(id='anotherID1') Hi
在相关的 Angular 指令中
$('#ID1').on('click', function() {alert('hi');}); // does not work
$('#anotherID1').on('click', function() {alert('hi');}); // works
我正在执行 DOM 操作,我需要 ng-repeat 元素的唯一 ID。还请建议是否也可以以任何其他方式执行 DOM 操作。
编辑:@tymeJV:-
style.
.ques {
height: 50px;
overflow:hidden;
}
<div ng-repeat='item in items'>
<div class='ques'> {{item.ques}}
</div>
<button id='ID{{$index}}'> No Hi </button>
</div>
// 指令代码:- 增加<div class = 'ques'>的高度
【问题讨论】:
-
只是想知道:你的模板引擎是什么:jade?span>
-
最终生成的html是什么。 id 属性在其中看起来如何?
-
请使用指令进行 DOM 操作! jQuery 风格的点击处理程序不是很 Angular-y。
-
@Chandermani angular 无法识别通过
ID{{$index}}生成的ID1,因此前一条语句无效 -
@tymeJV 我正在使用指令。上面的代码只是指令的一部分。但是里面有
jQuery。如果你可以建议替代代码。请做。
标签: angularjs angularjs-ng-repeat ng-repeat