You have unlimited access as a PRO member
You are receiving a free preview of 3 lessons
Your free preview as expired - please upgrade to PRO
Contents
Recent Posts
- Object Oriented Programming With TypeScript
- Angular Elements Advanced Techniques
- TypeScript - the Basics
- The Real State of JavaScript 2018
- Cloud Scheduler for Firebase Functions
- Testing Firestore Security Rules With the Emulator
- How to Use Git and Github
- Infinite Virtual Scroll With the Angular CDK
- Build a Group Chat With Firestore
- Async Await Pro Tips
Query Firebase Data With Angular Router URL Parameters
written by Jeff DelaneyThis snippet shows you how to use the Angular Router to make queries to the Firebase Realtime Database. It works by subscribing to the ActivatedRoute
, then using the params to make a query to Firebase with AngularFire2.
Structure Routes with URL Params
Adding variable URL params to an Angular route is simple. Just prefix it with a colon, such as :someId
.
app.routing.module.ts
const routes: Routes = [ |
Add Links with a FirebaseListObservable
In the list component, we will iterate of some records and use their $key
property in the URL as the :postId
param.
At this point, let’s assume our user has navigated to https://example.com/posts
.
post-list.ts
posts: any; |
post-list.html
<div *ngFor="let post of posts | async"> |
Make Queries with a FirebaseObjectObservable
When the user navigates to a given post, we can subscribe the params and make the query to Firebase as a FirebaseObjectObservable
.
After clicking a link, the user will be at a route the looks like https://example.com/posts/-KsOzIPzSZ4FXU06YdOw
.
post-object.ts
post: any |
post-object.html
Then you have the post object available as an Observable to unwrap in the HTML.
{{ post | async | json }} |