【发布时间】:2023-03-30 15:17:01
【问题描述】:
在由 ngFor 生成之后,我正在尝试在我的元素上绑定 jQuery UI 功能。因此,我正在寻找的是一个事件或我可以在我的组件中使用的东西,它提供了对创建的新元素的引用。 类似的东西:
sample.component.html
<!-- Parent div is the element I want a reference to each time it's created
so I can automatically bind the functionality -->
<div *ngFor="let item of items">
<img src="whatever.jpg">
<p> some other stuff here </p>
<div>
sample.component.ts
/* Something like Angular lifecycle hooks */
onNewElement(el) {
$(el).draggable();
}
是否有某种我可以使用的回调或在生成每个元素后触发的角度方法?有机会提供样品吗?
【问题讨论】: