我想在服务中设置一个firestore集合,以便以后返回一个可观察的文档
@Injectable()
export class ContactService {
private contactCollection: AngularFirestoreCollection<any>;
private contactDocument: AngularFirestoreDocument<any>;
constructor(
private authService: AuthService,
private afs: AngularFirestore
) {
this.authService.user
.subscribe(user => this.contactCollection = this.afs.collection(`directories/${user.uid}/contacts`));
}
getContacts(){
return this.contactCollection.valueChanges()
}
如果我导航到显示使用该服务的组件的路由,但是如果我直接访问该路由或刷新页面,则contactCollection未定义。
任何想法为什么会发生这种情况?