如果 REDUX 中的值正在从其他组件更新,则从 ngrx 选择器获取的 ngrx 可观察数据不会在订阅外部更新

ngrx observable data took from a ngrx selector is NOT getting updated outside subscribe if the value in REDUX is getting updated from other component

我的打字稿(简化组件)文件中有以下内容

public param_getting_updated_inHTML: number = 0;
public param_NOT_getting_updated_inHTML: number = 0;

ngOnInit(): void {
      this.store.select(selectorName).subscribe(
      (data) => { 
        this.param_getting_updated_inHTML= data;
      }
    );

    this.param_NOT_getting_updated_inHTML= this.param_getting_updated_inHTML+ 100;
}

我的(简体)HTML如下

<div> {{param_getting_updated_inHTML}}  </div> // this is getting updated properly if the value is changed from other place
<div> {{param_NOT_getting_updated_inHTML}}  </div> // (err) This is not getting updated 

this.param_NOT_getting_updated_inHTML = this.param_getting_updated_inHTML+ 100;

在改变param_getting_updated_inHTML var的订阅之外,所以它肯定会在订阅returns值和更新param_getting_updated_inHTML var之前被触发。因此,由于两个变量都初始化为值 0,param_NOT_getting_updated_inHTML 只会将 100 添加到 0,而一旦订阅 [=25],模板就会将 param_getting_updated_inHTML 显示为 0 以外的某个值=].

换句话说,如果你把

this.param_NOT_getting_updated_inHTML = this.param_getting_updated_inHTML+ 100;

在订阅下 - 当 param_getting_updated_inHTML 实际从商店获取它的值时 - 它会按预期工作。