This might work better for the getAccounts method:
getAccountsX() {
return this.afs.collection<Account[]>('accounts').snapshotChanges().map((accounts) => {
return accounts.map(a => {
const data = a.payload.doc.data() as Account;
const id = a.payload.doc.id;
return { id, ...data }
});
});
}
firestore , , ngOnInit .
, accounts: Observable<Account[]>
, Observable<Account[]>
getAccountsX(). * ngIf , : *ngIf="(accounts | async) as acts"
. dataSource acts
. DataTable, , , . , .
:
:
, , , Observable, , , :
accountsObservable: Observable<Account[]>;
accountsArray: Account[];
constructor(
private ds: DatabaseService
) {}
ngOnInit() {
this.accountsObservable = this.ds.getAccountsX();
this.accountsObservable.subscribe(accounts => {
this.accountsArray = accounts;
});
}
, , , * ngFor ASYNC-, , :
<div id="markup-subscription" *ngFor="let act of (accountsObservable | async)">
<p>{{ act?.id }}</p>
</div>
<div id="component-subscription" *ngFor="let act of accountsArray">
<p>{{ act?.id }}</p>
</div>
, . , , , * ngFor , DOM. *ngIf
accountArray, , :
<div id="component-subscription" *ngIf="accountsArray" *ngFor="let act of accountsArray">
, MatDataTable, , ,
, , , Observable :
const subscription = this.accountsObservable.subscribe(accounts => {
this.accountsArray = accounts;
});
subscription.unsubscribe();
, , .