簡體   English   中英

Angular, 如何在從服務器獲取數據並應用 *ngFor 后通過 Jquery 獲取類?

[英]Angular, How to get classes by Jquery after getting data from server and *ngFor has been applied for them?

我在 Angular 中使用 Jquery 和 typescript,我想獲取由 ngFor 循環生成的所有類。我正在構建一個產品站點......產品,我正在為它們應用 ngFor,在這個 ngFor 中我使用 class 名稱 imagePopup,當我運行此代碼時 let 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>

如果我可以提供建議,請不要將 jQuery 與 Angular 一起使用。 它會導致很多問題:/ 向我們展示您的代碼,我們會嘗試找出如何解決它:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM