I'm passing a user object into sessionStorage. When the next page is showing the string interpolation is not working. Even though the data is passed and the variable is filled.
export class ShoppingComponent implements OnInit, OnDestroy {
user: User;
private products: Product[] = [];
private cart: string[] = [];
private subscription: Subscription;
constructor(private shoppingService: ServiceShopping) { }
ngOnInit() {
// this.cart = this.service.getCart()
console.log("User: ", this.user);
this.subscription = this.shoppingService.getAllProducts().subscribe(
(products: Product[]) => {
console.log(products);
this.products = products
this.user = JSON.parse(sessionStorage.getItem('user'));
}
)
}
ngOnDestroy() {
this.subscription.unsubscribe()
}
}
here is the html:
<h4>Hello {{user.name}}</h4>
<hr>
<div class="row">
<app-shopping-item
*ngFor="let product of products"
[product]="product"></app-shopping-item>
</div>
the {{user.name}}
is not updating with the data