title: How can I get the value of localstorage at ngOnInit
body: <p>I need to display the username if the user is logged in. I have stored the username and token both to the localstorage. </p>
  
  <p>How can get the this user at the ngOnInit of navbar that I can display at the html.</p>
  
  <p>Here are my codes.</p>
  
  <h2>navbar.component</h2>
  
  <pre><code>export class NavbarComponent implements OnInit {
  
      public loggedIn: boolean;
      public user: any;
  
      constructor(private _authService: AuthService, private _router: Router) { }
  
      ngOnInit() {
          this._authService.authStatus
              .subscribe(
                  value =&gt; {
                      this.loggedIn = value
  
                  }
              );
      }
  </code></pre>
  
  <h2>auth.service</h2>
  
  <pre><code>export class AuthService {
  
      private loggedIn = new BehaviorSubject&lt;boolean&gt;(this._tokenService.loggedIn());
      //loggedIn change then change authstatus
      authStatus = this.loggedIn.asObservable();
  
      changeAuthStatus(value: boolean) {
          this.loggedIn.next(value);
      }
  
      constructor(private _tokenService: TokenService) {
          if (this._tokenService.loggedIn() == true)
              this._tokenService.getUser();
      }
  }
  </code></pre>