New to Angular. Wanted to learn how to manage state centrally so used ngRx. Also, have not used an Observable before so I am really stuck. Below is my code where the cart holds and array of objects. I just need to iterate over the cart
which is array of objects with reduce() to get a total of the price. No matter what I try it does not work. Just to add, up till this point my code is working fine and I am able to get cart data from the store.
Appreciate if someone can guide me in the right direction.
Thank you!
import { Component } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
@Component({
selector: 'app-cart-icon',
templateUrl: './cart-icon.component.html',
styleUrls: ['./cart-icon.component.scss']
})
export class CartIconComponent {
constructor(private store: Store<any>) {}
cart: Observable<Array<any>>
ngOnInit() {
this.cart = this.store.select('cart')
}
}