Is it possible -- from within a pipe --to query a Firebase database and return a value?
I have the following HTML
<div *ngFor="let item of items">
<h2>
{{item.firstName}} {{item.middleName}} {{item.lastName}}
</h2>
<div *ngFor="let lifeItem of (item.$key | event: 'life')">
Born: {{lifeItem.start}}
</div>
</div>
And the following pipe:
import { Pipe, PipeTransform } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
@Pipe({
name: 'event'
})
export class EventPipe implements PipeTransform {
subscriptions: Array<any> = new Array<any>();
items: Array<any> = new Array<any>();
constructor(
protected db: AngularFireDatabase
){}
public transform(personId: any, eventType: any) {
if (!personId || !eventType) return [];
console.info("personId: " + personId);
console.info("eventType: " + eventType);
this.subscriptions.push(
this.db.list('/event', {
query: {
limitToLast: 200
}
}).subscribe(items => {
console.info(items);
this.items = items;
return this.items;
})
);
}
}
When I run this, I get this in the console...
... but nothing is rendered in the corresponding section on the page.