我有此功能用于更新当前用户displayName
updateDisplayName(nameForm) {
if(nameForm.value.name === this.user.displayName) {
this.error = "Error: You used old name."
return
}
this.resetError();
var userRef = this.firebasePathCreator(this.currentUserId);
if (this.checkIfUserExists(this.currentUserId)) {
return userRef.update({
'displayName': nameForm.value.name,
'photoURL': ''
}).then(() => { this.navigateTo('/account'); });
} else {
return userRef.set({
'email': this.currentEmail,
'displayName': nameForm.value.name,
'photoURL': ''
}).then(() => { this.navigateTo('/account'); });
}
}
这将更新实时数据库和身份验证部分中的显示名称。但是当我路由到“/ account”时,displayName在我刷新页面之前不会改变。
html代码
<div class="large-6 columns">
<form [formGroup]="nameForm" (ngSubmit)="onSubmit(nameForm)">
<div class="row">
<div class="large-12 columns">
<h5>Change your name</h5>
<label [ngClass]="{error: (this.auth.error) }">
Full name
<input type="text" formControlName="name" value="{{ this.auth.currentUser.displayName }}">
</label>
<span class="error" *ngIf="this.auth.error">{{ this.auth.error }}</span>
</div>
</div>
<button type="submit" class="button small">Update</button>
</form>
</div>