Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度-当ngFor生成的每个元素';他创造了_Angular_Angular5_Ngfor - Fatal编程技术网

Angular 角度-当ngFor生成的每个元素';他创造了

Angular 角度-当ngFor生成的每个元素';他创造了,angular,angular5,ngfor,Angular,Angular5,Ngfor,我试图在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 --> <

我试图在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>

在生成每个元素后,是否可以使用某种回调或角度方法?有没有可能提供样品?

试试这个?span不会产生任何css问题

   <div *ngFor="let item of items"> 
      <span class="draggable">
        <img src="whatever.jpg">
        <p> some other stuff here </p>
      </span>
    <div>

这里还有别的东西


不要将JQuery与Angular一起使用。你不应该自己去触摸DOM,你应该让Angular去做

<div *ngFor="let item of items" #elements> 
    <img src="whatever.jpg">
    <p> some other stuff here </p>
<div>
这将为您提供可以使用渲染器操作的元素:

constructor(private renderer: Renderer2) {}

(请注意,您需要加载视图才能访问视图子项,这意味着最后一个可用的钩子是ViewInit之后的

这不仅不能回答问题,但是为什么不简单地将类放在div上呢?这样您就不能提供一些需要在初始化时动态计算和传递的属性和值。除jQuery方法外,我还需要动态绑定更多功能。因此,我需要知道正确的方法,就像@trichetriche提到的那样,非常感谢!顺便说一句,我已经看到很多人不鼓励使用jQuery,但它的功能在我的项目中至关重要。您是否知道其他一些模块(angular native与否)可以提供这种功能?如果您提到元素的可拖动性,请了解这一点,因此您真的不需要JQuery!
@ViewChildren('elements') els: QueryList<any>;
const first = this.els.first;
constructor(private renderer: Renderer2) {}