【发布时间】:2022-11-30 19:45:06
【问题描述】:
我遇到过
NG0100: ExpressionChangedAfterItHasBeenCheckedError
在我的 web 应用程序的在线产品部分,通过添加断点,我找到了问题的根源并添加了 settimeout。但是后来当我选择一个产品并想过滤那个产品时,我在同一个地方遇到了同样的错误。另外,我可以找到什么解决方案而不是settimeout? error-example
ngOnInit() {
const filterValue = "";
setTimeout(() => {
this._store$.dispatch(new OnlineProductsStoreActions.GetOnlineProducts(this.filter));
this._store$.dispatch(new OnlineProductsStoreActions.SearchProduct(filterValue, this.filter));
this._store$.dispatch(new OnlineProductsStoreActions.HomePageCategory());
this.onlineproductsEffects.getOnlineProductsHomePageCategory$
.pipe(
filter((action) => action.type === OnlineProductsStoreActions.ActionTypes.HOME_PAGE_CATEGORY_SUCCESS),
takeUntil(this.destroyed$)
)
.subscribe((res) => {
setTimeout(() => {
console.log(res);
this.SelectHomePageCategories = res;
}, 50);
});
this.productSearchSubscription = this.onlineproductsEffects.getOnlineProductsBySearch$
.pipe(
filter((action) => action.type === OnlineProductsStoreActions.ActionTypes.SEARCH_PRODUCT_SUCCESS),
takeUntil(this.destroyed$)
)
.subscribe((res) => {
setTimeout(() => {
this.onlineproducts = res;
this.dataSource = new MatTableDataSource(this.onlineproducts.payload);
console.log(this.onlineproducts);
}, 50);
});
我发现了问题及其所在,但需要比 settimeout 更多的信息...
【问题讨论】:
标签: angular