Here when I login to my app, i want to get json object stored in local Storage and then assign it to user Object. First time if I login it won't show anything but if I refresh the page I can see first name.
Here is .ts file
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
user: Object;
ngOnInit() {
this.user = JSON.parse(localStorage.getItem('user'));
}
}
And in template I want to use it like this:
<p> {{ user.first_name }} </p>
How can i solve this?
{{ user?.first_name }}
– Ali Shahzad Aug 23 '17 at 11:34