繁体   English   中英

无法在 firebase(ionic) 中为 angularfire2 列表名称使用变量

[英]Can’t use variable for angularfire2 list name in firebase(ionic)

我不能使用变量来保存我在 firebase 上的列表的名称。

在我推送一些数据后,变量在 firebase 中变得未定义。

$this.UserID用于保存 UID,但无法读取。

我的代码:

 private referenceListRef; UserID: string; constructor(private http: Http, private db: AngularFireDatabase, private ofAuth: AngularFireAuth, public storage: Storage ) { this.ofAuth.authState.take(1).subscribe(data => { this.UserID = data.uid; console.log(`user id : ${this.UserID}`); }) this.referenceListRef = this.db.list(`${this.UserID}`); }

您需要在subscribe()添加referenceListRef ,因为在this.ofAuth.authState Observable 完成之前您没有this.UserID

private referenceListRef;
UserID: string;

constructor(private http: Http, 
            private db: AngularFireDatabase,
            private ofAuth: AngularFireAuth,
            public storage: Storage
) {
    this.ofAuth.authState.take(1).subscribe(data => {
        this.UserID = data.uid;
        console.log(`user id : ${this.UserID}`);
        this.referenceListRef =  this.db.list(`${this.UserID}`); // <-- This code
    })
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM