typescript angularfire firestore
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript angularfire firestore相关的知识,希望对你有一定的参考价值。
import { Injectable } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from '@angular/fire/firestore';
import { GoldModel } from '../models/gold.model';
import { Observable } from 'rxjs/Observable';
import { UserModel } from '../models/user.model';
@Injectable()
export class FirebaseService {
usersCollection: AngularFirestoreCollection<UserModel>;
users: Observable<UserModel[]>;
userDoc: AngularFirestoreDocument<UserModel>;
constructor(private fire: AngularFirestore) {
//this.usersCollection = this.fire.collection('users');
//this.users = this.usersCollection.valueChanges();
}
getUsers() {
return this.users;
}
// update(gold: GoldModel) {
// this.userDoc = this.fire.doc(`users/${gold.id}`);
// this.userDoc.update(gold);
// }
isUserExist(id: string) {
this.userDoc = this.fire.doc<UserModel>(`users/${id}`);
return this.userDoc;
}
}
ngOnInit() {
this.firebaseService.isUserExist(this.firebase.auth.currentUser.uid).valueChanges()
.subscribe((data) => {
console.log('uid', this.firebase.auth.currentUser.uid);
console.log('firebase', data);
}, error => {
console.log(error);
});
}
以上是关于typescript angularfire firestore的主要内容,如果未能解决你的问题,请参考以下文章
typescript angularfire firestore
typescript AngularFire进口
如何解决 rxjs Typescript 错误(Ionic 3,angularfire2)
AngularFire2在Typescript中获取经过身份验证的用户ID
使用 Angular2、angularfire2 和 Typescript 从 Firebase 对象中获取数据
typescript AngularFire2 - 如果用户已登录则显示或隐藏