【发布时间】:2017-03-15 15:47:59
【问题描述】:
我一直在使用 angular2 和 firebase (angularfire2) 创建一个 Web 应用程序, 我想知道我的开发方法有没有优化。
当用户选择一个组时,我检查他是否已经是该组的成员。
ngOnInit() {
this.af.auth.subscribe(auth => {
if(auth) {
this.userConnected = auth;
}
});
this.router.params.subscribe(params=>{
this.idgroup=params['idgroup'];
});
this._groupService.getGroupById(this.idgroup).subscribe(
(group)=>{
this.group=group;
this.AlreadyPaticipe(this.group.id,this.userConnected.uid),
}
);
}
这种方法是可行的,但是当我将函数 AlreadyPaticipe(this.group.id,this.userConnected.uid) 放在 getGroupById(this.idgroup).subscribe() 之外时,我得到一个错误 group is undefined ,我现在因为 angular 是异步的。我不知道我该怎么做?如何优化我的代码?,如何将函数AlreadyPaticipe(this.group.id,this.userConnected.uid) 放在getGroupById(this.idgroup).subscribe() 之外
提前致谢。
【问题讨论】:
-
你不能,
AlreadyPaticipe的目的是什么? -
或者你可以使用解析
-
AlreadyPaticipe 是一个检查用户是否是组成员的功能。
标签: javascript angular firebase angularfire