0
注册并登录后,即时通知用户要创建一个配置文件。在那里我需要检查用户输入是否存在于分贝,如果不是创建配置文件。当你看到数据[0] [4 ] =数据库中的用户名。检查用户名是否存在于数据库中firebase angularfire2
带for循环im循环通过所有配置文件用户名来查找用户名存在或不。现在它创建配置文件,即使用户名存在。
感谢
https://image.prntscr.com/image/qDttSENCRqaOncLmpXNuhA.png
createProfile(){
this.allData=this.db.list(`/profile/`).valueChanges();
this.allData.take(1).subscribe(data => {
let data = data.map(this.getObjectWithoutKnowingKey);
console.log(data);
console.log(data[0][4]);
console.log(data.length);
console.log(this.username);
for(var i=0;0<data.length;i++){
if(data[i][4] === this.username){
console.log("username already exist");
return;
}
}
});
//if username exist dont execute this code below.
this.fire.authState.take(1).subscribe(auth => {
this.db.object(`profile/${auth.uid}/`).set({
username: this.username,
msgnumber: 0,
asd: 0,
avatar: this.avatar
});
this.db.object(`profile/${auth.uid}/inventory/`).set({
test: 1
}).then(() => this.navCtrl.setRoot(TabsPage));
});
}