Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as firebase from 'firebase';
- import firestore from 'firebase/firestore';
- import { environment } from '../environments/environment'; // here my configuration is
- const settings = {timestampsInSnapshots: true}
- ngOnInit(){
- firebase.initializeApp(environment.firebase);
- firebase.firestore().settings(settings);
- }
- ref = firebase.firestore().collection('orders');
- getOrders(): Observable<any> {
- console.log('on get orders snapshot');
- return new Observable((observer) => {
- this.ref.onSnapshot((querySnapshot) => {
- let boards = [];
- querySnapshot.forEach((doc) => {
- let data = doc.data();
- observer.next({
- driver_status: data.driver_status,
- food_status: data.food_status,
- });
- });
- observer.next(boards);
- });
- });
- }
- getOrder(id: string): Observable<any> {
- return new Observable((observer) => {
- this.ref.doc('ref-'+id).get().then((doc) => {
- let data = doc.data();
- observer.next({
- driver_status: data.driver_status,
- food_status: data.food_status,
- });
- });
- });
- }
- displayedColumns = ['driver_status', 'food_status'];
- dataSource = new OrderDataSource(this.fs);
- public fireOrder: Observable<any[]>;
- ngOnInit(){
- this.fs.getOrder(this.order.id).subscribe(res =>{
- this.fireOrder = res;
- });
- }
- --------------------------
- export class OrderDataSource extends DataSource<any> {
- constructor(private fs: FirebaseService) {
- super();
- console.log('in OrderDataSource constructor');
- this.connect();
- }
- connect() {
- console.log('in connect');
- return this.fs.getOrders();
- }
- disconnect() {
- }
- }
Add Comment
Please, Sign In to add comment