[英]Angular, How to get classes by Jquery after getting data from server and *ngFor has been applied for them?
I am using Jquery in Angular with typescript, I want to get all the classes that have been generated by ngFor loop.. I am building a products site... I am getting the products from node.JS Server... after I get the Products, I am applying ngFor for them, In this ngFor I am using a class name imagePopup, when I run this code let x = $('.imagePopup');我在 Angular 中使用 Jquery 和 typescript,我想获取由 ngFor 循环生成的所有类。我正在构建一个产品站点......产品,我正在为它们应用 ngFor,在这个 ngFor 中我使用 class 名称 imagePopup,当我运行此代码时 let x = $('.imagePopup'); I get x.length = 0;
我得到 x.length = 0; I'm not getting the classes from the ngFor loop.. How can I get all of them?
我没有从 ngFor 循环中获得课程。我怎样才能获得所有课程?
my Code:我的代码:
ngOnInit(): void {
this.productsSubjectSubscribe = this.localProductService.myProductsSubject.subscribe(x=> {
this.myProducts = x;
let y = $('.open-poup-image');
console.log(y);
});
}
console.log(y) gets length = 0 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>
If I can give advice, don't use jQuery with Angular.如果我可以提供建议,请不要将 jQuery 与 Angular 一起使用。 It causes lots of problems:/ Show us your code, and we try to figure out, how can we solve it:)
它会导致很多问题:/ 向我们展示您的代码,我们会尝试找出如何解决它:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.