我试图用Meteor实现Angular,并成功地实现了它。我试图以这种方式从我的收集中获取数据。这是我用来在表格中呈现数据的代码
<ng-container *ngFor="let product of products;let i=index">
<tr >
<td>{{ i+1}}</td>
<td>{{product.product_name}}</td>
<td >{{product.product_category_id
| fetch_product_category}}</td> // Approach 1
<td >{{getProductCateogry(product.product_category_id)}}
</td> // Approach 2
<td>{{product.product_brand}}</td>
<td>{{product.created_at | date}}</td>
<tr/>
</ng-container>
获取产品名称和品牌中的数据,但不获取产品类别Id中的数据。产品类别是一个不同的集合,其中包含类别名称。为了在Product Category中获取数据,我使用了这些方法1- Angular Pipe (我在Angular中使用过它)这是我创建的pipe类
@Pipe({
name: 'fetch_product_category'
})
export class FetchProductCategory implements PipeTransform {
private productCategory: any;
transform(catId: string): string {
var productCatListingSubs =
MeteorObservable.subscribe('fetch_product_category_based_on_categoryid',
catId).subscribe( => {
var productCategory =
ProductCategory.find({"product_category_id":catId}).fetch();
console.log("Products Category :",this.productCategory); // Getting Data Here
});
console.log("Products Category :",this.productCategory); // Data not returned here
return this.productCategory;
}
}
方法2:基于订阅获取数据
getProductSubcategory(catId){
var name;
console.log("Products Category"catId);
this.productCatListingSubs = MeteorObservable.subscribe('fetch_product_category_based_on_categoryid',catId).subscribe( => {
var productCategory = ProductCategory.find({"product_category_id":catId}).fetch();
console.log("Products Category",productCategory);
name = productCategory[0].product_category_name;
console.log("name :",name);
});
return name;
}
在第二种方法中,数据是存在的,但在控制台中有无限循环。我正在使用METEOR@1.8.0.1和ANGULAR@7.1.1这是一个很长时间以来的问题&不能解决这个问题,任何帮助都将不胜感激。
https://stackoverflow.com/questions/56335435
复制相似问题