|  | 
| 1 |  | -import { ApplicationRef, Component, NgZone, Optional } from '@angular/core'; | 
|  | 1 | +import { ApplicationRef, Component, NgZone } from '@angular/core'; | 
| 2 | 2 | import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; | 
| 3 | 3 | import { Auth, AuthInstances, authState } from '@angular/fire/auth'; | 
| 4 |  | -import { Firestore, FirestoreInstances } from '@angular/fire/firestore'; | 
| 5 |  | -import { firestoreInstance$ } from '@angular/fire/firestore'; | 
| 6 |  | -import { debounceTime } from 'rxjs/operators'; | 
| 7 |  | -import { initializeFirestore$ } from './firestore'; | 
|  | 4 | +import { Firestore, FirestoreInstances, getDoc, doc, DocumentSnapshot } from '@angular/fire/firestore/lite'; | 
|  | 5 | +import { DocumentData } from 'rxfire/firestore/lite/interfaces'; | 
|  | 6 | +import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; | 
| 8 | 7 | 
 | 
| 9 | 8 | @Component({ | 
| 10 | 9 |   selector: 'app-root', | 
| 11 | 10 |   template: ` | 
| 12 |  | -    <!--The content below is only a placeholder and can be replaced.--> | 
| 13 |  | -    <div style="text-align:center" class="content"> | 
| 14 |  | -      <h1> | 
| 15 |  | -        Welcome to {{title}}! | 
| 16 |  | -      </h1> | 
| 17 |  | -      <span style="display: block">{{ app.name }} app is running!</span> | 
| 18 |  | -      <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="> | 
| 19 |  | -    </div> | 
| 20 |  | -    <h2>Here are some links to help you start: </h2> | 
| 21 |  | -    <ul> | 
| 22 |  | -      <li> | 
| 23 |  | -        <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2> | 
| 24 |  | -      </li> | 
| 25 |  | -      <li> | 
| 26 |  | -        <h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2> | 
| 27 |  | -      </li> | 
| 28 |  | -      <li> | 
| 29 |  | -        <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2> | 
| 30 |  | -      </li> | 
| 31 |  | -    </ul> | 
|  | 11 | +    <pre>{{ (myDocData | async)?.data() | json }}</pre> | 
| 32 | 12 |     <router-outlet></router-outlet> | 
| 33 | 13 |   `, | 
| 34 | 14 |   styles: [] | 
| 35 | 15 | }) | 
| 36 | 16 | export class AppComponent { | 
|  | 17 | +  myDocData: Promise<DocumentSnapshot<DocumentData>>; | 
| 37 | 18 |   title = 'sample'; | 
| 38 | 19 |   constructor( | 
| 39 | 20 |     public app: FirebaseApp, // default Firebase App | 
| 40 | 21 |     public auth: Auth, // default Firbase Auth | 
| 41 | 22 |     public apps: FirebaseApps, // all initialized App instances | 
| 42 | 23 |     public authInstances: AuthInstances, // all initialized Auth instances | 
| 43 |  | -    @Optional() public firestore: Firestore, | 
| 44 |  | -    @Optional() public firestoreInstances: FirestoreInstances, | 
|  | 24 | +    public firestore: Firestore, | 
|  | 25 | +    public firestoreInstances: FirestoreInstances, | 
| 45 | 26 |     appRef: ApplicationRef, | 
| 46 | 27 |     zone: NgZone, | 
| 47 | 28 |   ) { | 
| 48 | 29 |     console.log({app, auth, apps, authInstances, firestore, firestoreInstances }); | 
| 49 |  | -    // onAuthStateChanged should destablize the zone | 
| 50 |  | -    // onAuthStateChanged(auth, it => console.log('onAuthStateChanged', it)); | 
| 51 | 30 |     authState(auth).subscribe(it => console.log('authState', it)); | 
| 52 |  | -    appRef.isStable.pipe(debounceTime(200)).subscribe(it => console.log('isStable', it)); | 
| 53 |  | -    firestoreInstance$.subscribe(it => console.log('$', it)); | 
| 54 |  | -    initializeFirestore$.subscribe(it => console.log('init', it)); | 
|  | 31 | +    appRef.isStable.pipe(distinctUntilChanged()).subscribe(it => console.log('isStable', it)); | 
|  | 32 | +    this.myDocData = getDoc(doc(firestore, 'animals/NJdGQCv1P92SWsp4nSE7')); | 
|  | 33 | +    // firestoreInstance$.subscribe(it => console.log('$', it)); | 
|  | 34 | +    // initializeFirestore$.subscribe(it => console.log('init', it)); | 
| 55 | 35 |   } | 
| 56 | 36 | } | 
0 commit comments