Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 2. then, we generate a service that can be used as bridge between these components
- */
- @Injectable()
- export class CurrentUserStoreService {
- // initial value with nnull or something else, for example undefined
- private currentUserSubject = new BehaviorSubject<User>(null);
- // some one might subscribe this to get real-time value, as below
- public currentUserSubject$ = this.currentUserSubject.asObservable();
- // some one might use this to change value
- setCurrentUser(user: User) {
- this.currentUserSubject.next(user);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement