angular - 如何过滤在 ngOnInit 期间检索到的值并将它们显示在屏幕上?
问题描述
我想在屏幕上显示那些 fastFoodShopList、 bakeryShopList、generalStoreList 变量,但不显示在屏幕上。
我已经确认正在使用 console.log 检索该值,但似乎在此之前正在显示屏幕。
如何在屏幕上显示这些变量?
ngOnInit() {
this.loaderService
.loadShopList(userInfo)
.pipe(takeUntil(this.onDestroy$))
.subscribe((shopTypeList) => {
this.fastFoodShopList = shopTypeList.filter((shop) => shop.type === 'fastFood')[0].shopList;
this.bakeryShopList = shopTypeList.filter((shop) => shop.type === 'bakery')[0].shopList;
this.generalStoreList = shopTypeList.filter((comment) => shop.type === 'generalStore')[0].shopList;
});
}
HTML 是这样的。
<div *ngFor="let fastFoodShop of this.fastFoodShopList; index as i">
<div class="row">
<div class="col-12">
<p>{{ fastFoodShop.shopName }}</p>
<p>{{ fastFoodShop.memo }}</p>
</div>
</div>
</div>
解决方案
我自己解决了。
我需要 markForCheck();
constructor(private cd: ChangeDetectorRef)
ngOnInit() {
this.loaderService
.loadShopList(userInfo)
.pipe(takeUntil(this.onDestroy$))
.subscribe((shopTypeList) => {
this.fastFoodShopList = shopTypeList.filter((shop) => shop.type === 'fastFood')[0].shopList;
this.bakeryShopList = shopTypeList.filter((shop) => shop.type === 'bakery')[0].shopList;
this.generalStoreList = shopTypeList.filter((comment) => shop.type === 'generalStore')[0].shopList;
this.cd.markForCheck();
});
}
推荐阅读
- anylogic - 在 AnyLogic 中,有没有办法在附加到代理时轻松指定资源的偏移量?
- r - mfrow3d 与 contour3d 擦除以前的图
- javascript - ReactJS useEffect 与 deps 相反
- swift - 我怎样才能使用这个功能来只回馈一个获胜者?
- nginx - nginx重定向后如何删除端口
- arrays - 如何获取从 json_agg() 查询返回的计数或记录?
- python-3.x - AttributeError:模块“cv2.cv2”没有属性“CreateMat”
- sql - 编写 PL/SQL 块,从 Employee 表中显示部门名称和部门的总工资支出
- multithreading - 多处理和多线程
- javascript - 将音频作为多部分/缓冲区休息