I am trying to make display properties in my component file html after http request. I get the properties displayed in my views but i still get an undefined error in my console. Here is my code
Here is my component.ts file
//// component.ts
import { AdminService } from './../../../../core/services/admin.service';
import { Store } from '@ngrx/store';
import { AppState } from 'src/app/core/store/state/app.state';
import { Logout } from './../../../../core/store/actions/login/login.action';
import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/core/models/user';
@Component({
selector: 'app-main-menu',
templateUrl: './main-menu.component.html',
styleUrls: ['./main-menu.component.scss']
})
export class MainMenuComponent implements OnInit {
user: any;
constructor(
private adminService: AdminService,
private store: Store<AppState>
) {
this.adminService.getAuthAdmin().subscribe(
(response: any) => {
this.user = response.data;
}
);
}
ngOnInit() {
}
logout(){
if (confirm('Are You Sure You Want To Logout?')) {
this.store.dispatch(new Logout());
}
}
}
component.html file
<div class="logged-user-info-w">
<div class="logged-user-name">
{{ user.full_name }}
</div>
<div class="logged-user-role">
Administrator
</div>
</div>
The exact error I am getting is
Cannot read property 'full_name' of undefined
Is there a workaround for this?