This is the exact error: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.ts(2322) (property) NavbarComponent.loggedInUser: string
Here is my code:
/* navbar-component-ts */
import { Component, OnInit } from '@angular/core';
import { AuthService } from 'src/app/services/auth.service';
import { Router } from '@angular/router';
import { FlashMessagesService } from 'flash-messages-angular';
import { Client } from '../../models/Client';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
/* Properties */
isLoggedIn!: boolean;
loggedInUser!: string;
showRegister!: boolean;
constructor(
private authService: AuthService,
private router: Router,
private flashMessage: FlashMessagesService
) { }
ngOnInit() {
this.authService.getAuth().subscribe(auth => {
if(auth) {
this.isLoggedIn = true;
this.loggedInUser = auth.email;
}else {
this.isLoggedIn= false;
}
})
}
}