title: Getting errors because it tries to render before I initialize my variables?
body: <p>I try to render a profile webpage using Angular.
  Here is my profile component:</p>
  
  <pre><code>export class ProfileComponent implements OnInit {
  
    currentUser : User;
    userVisited : User;
  
    constructor(public _userService:UserService, private  router:Router, private activatedRoute: ActivatedRoute) {
    }
  
    ngOnInit() {
      this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
      if(this.currentUser == null){
        this.router.navigate(['/']);
      }
      this.activatedRoute.params.subscribe((params: Params) =&gt; {
        this._userService.getUser(params['userId']).subscribe(res =&gt; {
          console.log (res);
          if(res.success){
            this.userVisited = res.user;
            console.log(this.userVisited.firstName);
          }
        });
      });
    }
  
  }
  </code></pre>
  
  <p>Now, I try to render <code>&lt;h1&gt;{{userVisited.firstName}} {{userVisited.lastName}}&lt;/h1&gt;</code>. But it gives me at first in the console errors :</p>
  
  <pre><code>TypeError: Cannot read property 'firstName' of undefined
  </code></pre>
  
  <p>Then, it still renders the right <code>firstName</code> and <code>lastName</code>because it seems those errors are printed before it went through the Init function.</p>
  
  <p>Any ideas on how to avoid those errors?</p>