Angulaire.io / Angulaire 4. Comment puis-je actualiser un composant de la vue lors du déclenchement d'un autre

J'ai un simple Angulaire.io app. (angulaires-cli /4.1.0)

J'ai un NavbarComponent qui rend le nom d'utilisateur.

Lors de l'accès à l'application la première fois que je ne suis pas connecté et mon application redirige vers la LoginComponent. Ma barre de navigation est également rendu mais sans un nom d'utilisateur. Une fois la connexion réussie, je suis redirigé vers mon HomeComponent.

Et là est le problème. Ma NavBar ne pas afficher le nom d'utilisateur. Mais si je fais un refresh/ctrl+r le nom d'utilisateur est rendu.

Quel est le problème?

app.component.html

<nav-bar></nav-bar>
<router-outlet></router-outlet>

barre de navigation.le composant.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'nav-bar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {

  me;

  ngOnInit() {
    this.me = JSON.parse(localStorage.getItem('currentUser'));
  }
}

de connexion.composante.ts

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';

import { AlertService, AuthenticationService } from '../_services/index';

@Component({
    moduleId: module.id,
    templateUrl: 'login.component.html'
})

export class LoginComponent implements OnInit {
    model: any = {};
    loading = false;
    returnUrl: string;

    constructor(
        private route: ActivatedRoute,
        private router: Router,
        private authenticationService: AuthenticationService,
        private alertService: AlertService) { }

    ngOnInit() {
        //reset login status
        this.authenticationService.logout();

        //get return url from route parameters or default to '/'
        this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
    }

    login() {
        this.loading = true;
        this.authenticationService.login(this.model.email, this.model.password)
            .subscribe(
                data => {
                    this.router.navigate([this.returnUrl]);
                },
                error => {
                    this.alertService.error(error);
                    this.loading = false;
                    this.errorMsg = 'Bad username or password';console.error('An error occurred', error);
                });
    }
}

OriginalL'auteur ChrisWorks | 2017-05-03