I'm using material 2, and I'm trying to create data tables with pagination and sorting, so I need my collections to be observable, but I think I must be populating/initialising the arrays incorrectly in the controller.
I've been populating an 'expenses' array with data from an 'expenses' firestore collection using the method below, but this always says "Type 'Observable<{}[]>' is not assignable to type 'any[]'"...
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { MatPaginator, MatTableDataSource, MatSort } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
@Component({
selector: 'app-expense-list',
templateUrl: './expense-list.component.html',
styleUrls: ['./expense-list.component.scss']
})
export class ExpenseListComponent implements OnInit, AfterViewInit {
tableColumns = [ 'id' ];
expenses: any[];
constructor(private db: AngularFirestore) {
this.expenses = this.db.collection('/expenses').valueChanges();
}
ngOnInit() {
}
ngAfterViewInit() {
}
viewExpense(row) {
console.log('viewExpense(' + row.id + '): ', row);
}
}
How do I properly create an observable array that's populated with data from a firestore collection?