代码之家  ›  专栏  ›  技术社区  ›  Vueer

无法访问来自角度服务的代码

  •  0
  • Vueer  · 技术社区  · 7 年前

    我正在使用本地存储( https://github.com/cyrilletuzi/angular-async-local-storage TypeError: Cannot read property 'subscribe' of undefined .

    PS:本例中绝对不存在值“user”。

    我就是这么想的

    getDbFromUser(uid) {
    
        this.localStorage.getItem('user').subscribe((data) => {
          if (data) {
            console.log(data);
          } else {
            console.log('Nothing found');
            // Load data from Firebase
            this.dataObjRef = this.afDatabase.object(`data/users/${uid}`);
            this.data = this.dataObjRef.valueChanges();
            return this.data;
          }
        }, () => {
        })
      }
    
    0 回复  |  直到 7 年前
        1
  •  2
  •   Shashank Vivek    7 年前

    检查 this demo link .

    this.localStorage.setItem('user', user).subscribe(() => { });
    

    一旦设置了该值,然后重新加载带有注释行的页面。

    如果这没有帮助,请随时联系我们 它可以复制场景并让我知道

        2
  •  1
  •   dardardardar    7 年前

    var user = localStorage.getItem('user');
    if(typeof user === 'undefined') {
       // do you firebase syncing here.
    }