【发布时间】:2019-01-10 23:45:40
【问题描述】:
我的问题是我正在显示 Firebase 数据库中的所有数据,但它还包括当前登录的用户的数据。例如,如果用户的个人资料包含:firstName = "Sasha", lastName = "Parks", language = "Creole",她会在显示的数据上看到她自己的个人资料。
如何修改这段代码来隐藏她自己的数据?
我页面的ts文件:
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ProfilePage } from '../profile/profile';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase } from 'angularfire2/database';
import { Profile } from '../../models/profile.interface';
import { Observable } from 'rxjs';
@Component({
selector: 'page-matches',
templateUrl: 'matches.html'
})
export class MatchesPage {
profile = {} as Profile;
profileData: Observable<Profile[]>;
goProfilematches = ProfilePage;
constructor(private afAuth: AngularFireAuth, private db: AngularFireDatabase,
public navCtrl: NavController) {
}
ionViewWillLoad(){
this.afAuth.authState.subscribe(data => {
if (data && data.email && data.uid) {
this.profileData = this.db.list('profile/'+data.uid).valueChanges();
} else {
}
});
}
}
html:
<ion-header>
<ion-toolbar>
<ion-buttons start>
<button ion-button [navPush]="goProfilematches">
<ion-icon name="contact"></ion-icon>
</button>
</ion-buttons>
<ion-title>Matches</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item *ngFor="let profile of profileData | async">
<h1>First Name: {{profile?.firstName}}</h1>
<p>Last Name: {{profile?.lastName}}</p>
<p>Language: {{profile?.language}}</p>
</ion-item>
</ion-list>
</ion-content>
Firebase 数据库分为身份验证和实时数据库部分,用户在其中使用电子邮件和密码进行注册,然后填写存储在实时数据库中的配置文件。
任何帮助表示赞赏! 任何帮助总是受到赞赏。谢谢!!
【问题讨论】:
标签: typescript firebase ionic-framework firebase-authentication ionic3