I have a web app that makes a request to firebase realtime database for user information.
The info is returned when the service calls the method below:
//searches db for user information
getUserInfo(uid){
return this.db.list('users/', ref => ref.orderByKey().equalTo(uid)).valueChanges();
}
This method is triggered inside a pipe defined like so:
@Pipe({
name: 'usernamePipe'
})
export class UsernameFilter implements PipeTransform{
constructor(private auth: AuthenticationService){
}
transform(uid: any):any {
//return item if neither filter nor list exists
if(!uid){
return uid;
}
var user = {};
this.auth.getUserInfo(uid)
.subscribe(res => {
user = res;
return user[0].userInfo.firstName;
})
}
}
The pipe is used on a list of messages obtained by a call to my realtime database inside my component like so:
<div class="message-summary" *ngFor="let msg of messageThread.messages | keys; let last = last" (click)="getThreadDetails(messageThread.messages)">
<span class="time">{{msg.timeSent | date: 'short'}}</span>
<span class="sender-name" *ngIf="msg.from !== 'admin'">{{msg.from | usernamePipe | async}}</span>
</div>
The keys
pipe is another custom pipe I used to turn the objects returned from the initial request to the realtime database into an array in order to iterate over with *ngFor
Issue is that the transformed data doesn't show up in the DOM but if I try logging it to console, it shows up - proving that the method works but it's not displaying for some reason.