From 8a3641e2d60a74b609e247cb934efaaa676c399b Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Mon, 5 Apr 2021 15:01:10 -0500 Subject: [PATCH] Fix ExpressionChangedAfterItHasBeenCheckedError going from logged in to /logout --- src/app/components/main/main.component.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/components/main/main.component.ts b/src/app/components/main/main.component.ts index d1608c63..6f111129 100644 --- a/src/app/components/main/main.component.ts +++ b/src/app/components/main/main.component.ts @@ -1,15 +1,16 @@ -import { Component, AfterContentInit } from '@angular/core'; +import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core'; import {AuthenticatedUser, AuthService} from '../../services/authentication.service'; -import {MAIN, LOGIN} from '../../constants/routes'; +import {MAIN} from '../../constants/routes'; import { Router, ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-main', templateUrl: './main.component.html', - styleUrls: ['./main.component.styl'] + styleUrls: ['./main.component.styl'], + changeDetection: ChangeDetectionStrategy.OnPush }) -export class MainComponent implements AfterContentInit { - public currentUser: AuthenticatedUser; +export class MainComponent implements OnInit { + public currentUser: AuthenticatedUser = null; private afterLoginRoute: string; constructor( @@ -21,7 +22,7 @@ export class MainComponent implements AfterContentInit { this.afterLoginRoute = MAIN; } - ngAfterContentInit() { + ngOnInit() { if (this.authService.isLoggedIn()) { this.authService.getUserInfo(); }