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));
});
}