I am learning Angular. I am trying to achieve, after the logged in the page redirect to homepage. Following I have tried,
app.component.html
<header *ngIf='loggedIn'>
<h1>Test portal</h1>
</header>
<login *ngIf='!loggedIn' (homeVar)="loadHome()">Loading..</login>
<router-outlet></router-outlet>
app.component.ts
export class AppComponent implements OnInit {
  loggedIn = 0;
  constructor(private router:Router){}
  ngOnInit(){
    if(!this.loggedIn){
      this.router.navigate(['']);
    }
  }
    loadHome():void{
      this.loggedIn=1;
      this.router.navigate(['home']);
  }
}
login.component.ts
export class loginComponent implements OnInit  {
    @Output() homeVar:EventEmitter<string> = new EventEmitter();
    @SessionStorage() session:any = "";
    ngOnInit(){
        if(this.session != ""){
            this.homeVar.emit(this.session);
        }
    }
   check(){
      this.session = "user";
   }
 }
The above code is working fine but it is giving the following error
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: 0'. Current value: 'ngIf: 1'.
How to fix this problem?
 
     
     
    