如何从angularfire2 cloud firestore获取新创建的自动生成的ID
How to get newly created auto generated ID from angularfire2 cloud firestore
我正在尝试从 firestore 新创建后获取自动生成的 ID,但我不知道为什么当我 console.log(ref)
时,它是 undefined
,请查看我的代码:
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
@Injectable()
export class UserProvider {
usersCollectionRef: AngularFirestoreCollection<any>;
constructor(public http: HttpClient, public firestore: AngularFirestore) {
this.usersCollectionRef = this.firestore.collection<any>('users');
}
addUpdateContact(name: string, email: string) {
const newId = this.firestore.createId();
this.usersCollectionRef.doc(newId).set({ username: name, email: email }).then(ref => {
console.log(ref);
});
}
}
它设法成功地将数据插入到 firestore 中
我正在使用 ionic 3
和 angularfire2
5.4.2
我已经尝试了 的解决方案,但它不起作用...请帮助我,谢谢
我正在尝试从 firestore 新创建后获取自动生成的 ID,但我不知道为什么当我 console.log(ref)
时,它是 undefined
,请查看我的代码:
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
@Injectable()
export class UserProvider {
usersCollectionRef: AngularFirestoreCollection<any>;
constructor(public http: HttpClient, public firestore: AngularFirestore) {
this.usersCollectionRef = this.firestore.collection<any>('users');
}
addUpdateContact(name: string, email: string) {
const newId = this.firestore.createId();
this.usersCollectionRef.doc(newId).set({ username: name, email: email }).then(ref => {
console.log(ref);
});
}
}
它设法成功地将数据插入到 firestore 中
我正在使用 ionic 3
和 angularfire2
5.4.2
我已经尝试了