I’m new to Firebase and Angular and I’m making a Twitter mock-up for practice. I have it to where a user can make a Post and it saves to a collection of ‘posts’ in Firebase. Now, I’m trying to get it to where the most recent post displays on the HomePage for a start.
import { Injectable } from '@angular/core';
import { Post } from 'src/interface';
import { AngularFirestore } from '@angular/fire/firestore';
@Injectable({
providedIn: 'root'
})
export class PostsService {
postsCollection = this.afs.collection<Post>('posts');
constructor(private afs: AngularFirestore) {
}
const recentPostQuery: Query<Post> = this.postsCollection.ref.orderBy('timestamp', 'desc').limit(1);
}
Obviously this code doesn’t work. Am I getting close though? How should I set up the observable in this scenario? Any help is appreciated thank you
New contributor
WillKro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.