【发布时间】:2018-05-22 10:34:10
【问题描述】:
我有一个如下所示的异步方法。它在此处显示错误[ts] 'await' expression is only allowed within an async function. await userProfile.set({。能告诉我怎么解决吗?
注意:可能是因为我尝试在observable 中调用promise。有什么线索吗?
async loginWithGoogle(): Promise<void> {
const result = await this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
const userId: string = result.uid;
const userProfile: AngularFirestoreDocument<UserProfile> = this.fireStore.doc(`userProfile/${userId}`);
const userProfiles: AngularFirestoreCollection<UserProfile> = this.fireStore.collection('userProfile/', ref => ref.where('email', '==', result.email));
const userProfiles$: Observable<UserProfile[]> = userProfiles.valueChanges();
userProfiles$.subscribe(res => {
if (res == null) {
await userProfile.set({ //here it shows error
id: userId,
email: result.email,
creationTime: moment().format(),
lastSignInTime: moment().format()
});
}
});
}
【问题讨论】:
标签: angular rxjs ionic3 angularfire2 google-cloud-firestore