title: Angular 2 how to pass data between different components
body: <p>I have two different components: one is a <em>login</em> component and the other is <em>users</em> component.</p>
  
  <p>In the login component I am authenticating with <code>MakeLogin</code> function and after that getting user details from API and navigating by route to the home page (in the home page the users component is initiated)</p>
  
  <p>The user details that I am getting from the API are saved to an object <code>UserItem</code>. This object needs to be alive in the users component and I cant manage to do that </p>
  
  <p>I would like to know what is the best method to get it work </p>
  
  <p>Thanks !</p>
  
  <p>The Login Component : </p>
  
  <pre><code>export class LoginComponent implements OnInit{
      token : string;
      loginDetails : LoginItem;
      LoginStatus : boolean;
      error : string;
      private loader = false;
      currentUser : UserItem;
  
      constructor(private LoginService : LoginService,private router : Router){}
  
      ngOnInit(){
          this.LoginStatus = this.LoginService.CheckLoginStatus();
          if(this.LoginStatus === true){
              this.router.navigate(['']);
          }
      }
  
      MakeLogin(Email:string,Password:string) {
          this.error = null;
          this.loader = true;
          this.loginDetails = new LoginItem(Email,Password);
          this.LoginService.PostLogin(this.loginDetails).subscribe(data =&gt; {
              if(data === true){
                  this.token = localStorage.getItem('id_token');
                  this.UsersService.GetUserDetailsFromDB(this.token).subscribe(data =&gt;{
                      this.currentUser = new  UserItem(data.firstName,data.lastName,data.email,data.id);
                      this.router.navigate([''])
                   });
              }
          }, error =&gt;{
              if(error === 401){
                  console.log(error);
                  this.loader = false;
                  this.error = "Username or Password incorrect";
              }
          });
      }
  }
  </code></pre>