Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /*
  2. 2. then, we generate a service that can be used as bridge between these components
  3. */
  4.  
  5. @Injectable()
  6. export class CurrentUserStoreService {
  7. // initial value with nnull or something else, for example undefined
  8. private currentUserSubject = new BehaviorSubject<User>(null);
  9.  
  10. // some one might subscribe this to get real-time value, as below
  11. public currentUserSubject$ = this.currentUserSubject.asObservable();
  12.  
  13. // some one might use this to change value
  14. setCurrentUser(user: User) {
  15. this.currentUserSubject.next(user);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement