Angular,如何在从服务器获取数据后通过 Jquery 获取类并且 *ngFor 已应用于它们?

问题描述

我在带有打字稿的 Angular 中使用 Jquery, 我想获取 ngFor 循环生成的所有类.. 我正在建立一个产品网站... 我正在从 node.JS 服务器获取产品... 在我拿到产品后,我正在为他们申请 ngFor, 在这个 ngFor 中,我使用了一个类名 imagePopup, 当我运行此代码时 让 x = $('.imagePopup'); 我得到 x.length = 0; 我没有从 ngFor 循环中获取类.. 我怎样才能获得所有这些?

我的代码

ngOnInit(): void {
   this.productsSubjectSubscribe = this.localProductService.myProductsSubject.subscribe(x=> {
       this.myProducts = x;
       let y = $('.open-poup-image');
       console.log(y);
   });
}

console.log(y) 得到长度 = 0

<div *ngFor="let item of myProducts;index as i" class="item" [id]="'item_'+item._id">
     <div class="item_img">
          <a class="open-poup-image"
            [href]="'src-to-image.jpg">Open
            image</a>
          <img
            [src]="src-to-image.jpg">
        </div>
</div>

解决方法

如果我可以提供建议,请不要在 Angular 中使用 jQuery。它会导致很多问题:/ 向我们展示您的代码,我们会尝试找出如何解决它 :)