问题描述
有人在您为Firebase中的文档分配了一个引用(还不存在,它只是一个地方),然后在其中放置文字对象而它却没有出现时,是否遇到过这样的问题?
interacting-with-firebase.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { from,Observable,of } from 'rxjs';
import { User } from '../../classes/user';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore} from 'angularfire2/firestore';
import { switchMap } from 'rxjs/operators';
public signup(name: string,surname: string,email: string,password: string,photoUrl: string): Observable<boolean> {
return from(this.angularFireAuth.auth.createuserWithEmailAndPassword(email,password).then(userCredentials=> {
const dieBenutzerreferenz = this.angularFirestore.doc(`chatUsers/${userCredentials.user.uid}`);
const updatedUser = {
id: userCredentials.user.uid,email: userCredentials.user.email,name,surname,photoUrl
};
dieBenutzerreferenz.set(updatedUser);
return true;
}).catch(
(error) => false
));
} // end of signup(){}
从昨天开始我一直在研究它,很遗憾,我没有任何人可以咨询它(我自己构建了第一个应用程序),而且我的眼睛红了。谢谢。 我仍然使用AngularFire2,但是不管怎么说,直到最近它对我有用,现在却不起作用。
user.ts
export class User {
id: string;
email: string;
name: string;
surname: string;
photoUrl: string;
constructor({id,email,photoUrl}) {
this.id = id;
this.email = email;
this.name = name;
this.surname = surname;
this.photoUrl = photoUrl;
}
}
解决方法
方法set
是一个async
函数,因此您需要await
或等待诺言。