[英]Return true of false if key is true
我想仅在当前用户是我使用checkGuest(event.$key)
检查的来宾时显示事件
<md-card class="home-card" *ngFor="let event of events | async">
<a *ngIf="checkGuest(event.$key)" [routerLink]="['event', event.$key]">
<img class="event-home-img" src="https://lorempixel.com/300/300" />
<p class="home-page-title">{{ event.name }}</p>
<p class="home-page-venue">{{venueName}}</p>
</a>
</md-card>
Firebase列表eventsGuestsLookup
如下所示:
{
"uid1" : {
"-Ktm57w59Q_2c48r6ntx" : true,
},
"uid2" : {
"-KtmbLqT0U005Ndelw3S" : true,
"-KtmcLr44X0ho1NZP_h_" : true,
"-KtmdP2BKzhwezxa-Lbl" : true,
"-KtoGScCD7Zq4N3KkQQG" : true
}
}
this.uid
是uid2
和eventKey
是-Ktm57w59Q_2c48r6ntx
事件的关键是不是即使在uid2
列表。 我希望this.hello
返回false,但是正在为用户uid2
显示数据库中的唯一事件……我在做什么错?
checkGuest(eventKey: string): Observable<Boolean> {
const event = this.db.object(`eventsGuestsLookup/${this.uid}/${eventKey}`);
return event.map(e => this.hello(e));
}
hello(e): Boolean {
if (e) {
return true;
}
return false;
}
您正在使用Boolean
对象而不是boolean
元。 这可能是问题吗?
编辑/更新(2017年9月13日):
我根本没有使用过angularfire
,但是从您的代码来看,它看起来像您的ngIf
谓词函数checkGuest()
,正在返回FirebaseObjectObservable<boolean>
,无论它的boolean
值如何,它truthy
是truthy
(因为它被包装了)作为可观察到的)。
我想如果您将checkGuest()
方法更改为此,
checkGuest(eventKey: string): boolean {
return this.db.object(`eventsGuestsLookup/${this.uid}/${eventKey}`)
.subscribe((e) => this.hello(e.$value));
}
它可能会起作用。 如果您仍在寻找答案,请尝试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.