Angular订阅变量不显示

问题描述

我正在处理一些用户管理代码。基本上,单击按钮后,我希望它保存一个新用户,然后显示我保存在商店中的输入密码。我的代码看起来像这样:

onClick() {
/*Insert filling up the newUser variable from the form here*/
this.store.dispatch(new AddUser(this.newUser)) 
    this.store.select(userFeature.getPassword).subscribe(
      pass => {
      this.temp = pass; //I've tried using this.password here,but also nothing
    })
    setTimeout(() => {
      this.pause();
    },5000);
    //this.password = "Stuff" <-- This DOES work
    this.password = temp //This executes despite the wait above
}

pause(){
    if(this.temp === null){
        setTimeout(() => {
          this.pause();
        },500);
        console.log("Waiting...")
      }
}

在我的HTML中,我在一个简单的跨度中使用{{password}}。

编辑:已修复!我需要使用ChangeDetectorRef。

this.store.dispatch(new AddUser(this.newUser))
    this.store.select(userFeature.getPassword).subscribe(
      pass => {
      this.password = pass;
      this.cd.detectChanges();
      });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)