Reputation: 14520
This might be a simple question but can't figure it out. When I load up my site I call a service that fetches user data
private currentUserSource = new ReplaySubject<IUser>(1);
currentUser$ = this.currentUserSource.asObservable();
// call to controller left out for brevity
// then pass user to replaysubject here
this.currentUserSource.next(user);
I can access the values in my html file with an async call like this
(currentUser$ | async).someProperty
But how do I access the values in typescript?
Upvotes: 0
Views: 861
Reputation: 2593
You can subscribe to the event:
import * as Rx from "rxjs";
const subject = new Rx.ReplaySubject(1);
subject.subscribe((user) => {
console.log('User Id:', user.id);
});
subject.next({
id: 1,
name: "jon"
});
Upvotes: 1