NGRX-从子组件到app.component的订阅

NGRX-从子组件到app.component的订阅,ngrx,Ngrx,我必须根据子组件数据有条件地在应用程序组件上显示footercomponet。我从应用组件全局商店更新订阅,当子组件更新商店时,我没有看到应用组件订阅被触发。我使用的angular 6是应用程序组件上的原型代码 代码-AppComponent-> public ngOnInit(): void { this.subscriptions.push(this.store.pipe(select(showFooterFun)).subscribe(showfooter => {

我必须根据子组件数据有条件地在应用程序组件上显示footercomponet。我从应用组件全局商店更新订阅,当子组件更新商店时,我没有看到应用组件订阅被触发。我使用的angular 6是应用程序组件上的原型代码

代码-AppComponent->

public ngOnInit(): void {      
this.subscriptions.push(this.store.pipe(select(showFooterFun)).subscribe(showfooter => {
      this.showLegalFooter = showfooter;
    }));
}

子组件-我让子组件使用布尔值更新全局存储以显示隐藏页脚。是否可以通过更新全局存储从子级调用app.component subscription。

请不要
subscription
,这通常是一些事情不起作用的情况。 相反,使用Angular的内置
async
管道。 还要确保您正在以一种纯粹的方式修改减速器中的状态

// in typescript
showFooter$ = this.store.pipe(select(showFooterFun);

// in html
<div *ngIf="showFooter$ | async">
Footer
</div>
//在typescript中
showFooter$=this.store.pipe(选择(showFooterFun));
//在html中
页脚

谢谢timdeschryver的回复/建议非常感谢我没有尝试过你建议的方法,但在进一步调试时,我发现在我的情况下,由于应用程序组件中出现异常ngOnInit订阅被取消订阅,通过设置空检查,我发现它得到了解决

this.subscriptions.push(this.store.pipe(select(showLegalFooter)).subscribe(showfooter => {
  if (showfooter) { //null check resolved the issue
    this.showFooter = showfooter.showFooter; //earlier when showfooter was null //which lead to exception and the suscription got unsuscribe.
              }
}));