Как обновить вид с объекта из sessionStorage? - PullRequest
0 голосов
/ 20 сентября 2019

Я передаю объект пользователя в sessionStorage.Когда на следующей странице показывается строка, интерполяция не работает.Даже если данные передаются и переменная заполнена.

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()
 }

 }

здесь html:

<h4>Hello {{user.name}}</h4>
<hr>
<div class="row">
        <app-shopping-item 
        *ngFor="let product of products"
        [product]="product"></app-shopping-item>
</div>

{{user.name}} не обновляется с данными

...