在我的离子应用程序中,注册并登录后,数据会保存在Firebase中,但是当用户登录或注销时,我不知道如何在首页中隐藏或显示内容。
在我的authentication.service.ts中,当用户登录时设置了uid(用户ID)
async signIn(email, password){
try{
let userData = await this.afAuth.auth.signInWithEmailAndPassword( email, password);
this.uid = this.afAuth.auth.currentUser.uid;
return { success: true, uid: this.uid, email: email };
}
catch(error){
return { success: false, error: error.message };
}
}
home.page.html
<ion-card-content>
sign up here
<ion-button class="btnSignUp" fill="clear" color="medium" (click)="showSignup()">
Sign up
</ion-button>
</ion-card-content>
所以我想在authentication.service.ts中使用该信息,并且仅当用户未登录时才在home.page.html中显示该注册按钮。
答案 0 :(得分:0)
在您的<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
中执行以下操作:
home.page.ts
然后在您的HTML中:
export class Home implements OnInit{
currentUser : any;
showBtn : boolean = true;
constructor(public afAuth: AngularFireAuth) {}
ngOnInit(){
this.currentUser = this.afAuth.auth.currentUser;
if(this.currentUser === null){
this.showBtn = false;
}
}
在这里,您首先检索<ion-card-content *ngIf="showBtn">
sign up here
<ion-button class="btnSignUp" fill="clear" color="medium" (click)="showSignup()">
Sign up
</ion-button>
</ion-card-content>
,如果用户未登录,则可以将currentUser
分配给showBtn
,然后在html中使用false
显示/隐藏按钮。