I'm trying to subscribe to an Observable so I can display it in HTML with Angular, doing console.log(player) works fine however I get
Type 'Player' is missing the following properties from type 'Observable<Player>': _isScalar, source, operator, lift, and 6 more.ts(2740)
I've tried using .pipe(),
HTML:
<div *ngIf="(player$ | async) as player">
<div *ngIf="player.characterUid">
{{player.characterName}}
</div>
</div>
Component:
player$: Observable<Player>;
subPlayer: Subscription;
selectPlayer(matEvent: MatAutocompleteSelectedEvent): void {
this.inputFriends = matEvent.option.value;
this.selectedPlayer = matEvent.option.value;
this.inputP = false;
this.subPlayer = this.playerProvider.get$(matEvent.option.value.userUid).subscribe(
(player: Player) => {
this.player$ = player; // Type 'Player' is missing the following properties from type 'Observable<Player>': _isScalar, source, operator, lift, and 6 more.ts(2740)
}
);
}
Provider:
get$(uid: string): Observable<Player> {
return this._getDoc(uid)
.valueChanges()
.pipe(
map((sPlayer: ServerPlayer) => sPlayer ? new Player(sPlayer) : null)
);
}
private _getDoc(uid: string): AngularFirestoreDocument {
return this.afs.doc(`players/${uid}`);
}
I'm just trying to assign player$ so I can display it in the HTML