Guest User

Untitled

a guest
Aug 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Service
  2.  
  3.   currentUser: BehaviorSubject<ApplicationUser>;
  4.  
  5.   constructor(private http: HttpClient, private router: Router) {
  6.     this.currentUser = new BehaviorSubject(JSON.parse(localStorage.getItem('currentUser')));
  7.   }
  8.  
  9. ## Component
  10.   currentUser: ApplicationUser;
  11.  
  12.   ngOnInit() {
  13.     this.authService.currentUser.subscribe((userData: ApplicationUser) => { this.currentUser = userData; });
  14.   }
  15.  
  16. ## Setter of currentUser
  17.   func() {
  18.     const user: ApplicationUser = {
  19.       Email: 'as',
  20.       Id: 'a12'
  21.     };
  22.     this.authService.currentUser.next(user);
  23.   }
Advertisement
Add Comment
Please, Sign In to add comment