File

src/app/cart/cart-components/components/shopping-cart-icon/smart/shopping-cart-icon.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector shopping-cart-icon
template
<shopping-cart-icon-ui    [cartItemsCount]="numberOfBooksInCart$ | async"
    [animating]="animating$ | async"
    [openDropDown$]="isDropDownVisible$"
    (onIconClick)="iconClicked()"></shopping-cart-icon-ui>

Index

Properties
Methods

Constructor

constructor(store: Store)
Parameters :
Name Type Optional
store Store<any> No

Methods

iconClicked
iconClicked()
Returns : void

Properties

animating$
Type : Observable<boolean>
isDropDownVisible$
Type : Observable<boolean>
numberOfBooksInCart$
Type : Observable<number>
import { Component, ChangeDetectionStrategy } from "@angular/core"

import { Observable } from 'rxjs'
import { Store, select } from '@ngrx/store'

import { selectCartStatusBooksCount } from '../../../../cart-data/selectors/cart-status.selectors'
import { selectCartIconAnimatingStatus, selectCartIconDropDownIsVisible } from '../../../../cart-data/selectors/cart-icon.selectors'
import { toggleCartIconDropDown } from '../../../../cart-data/actions/cart-icon.actions'

@Component({
  selector: 'shopping-cart-icon',
  template: `<shopping-cart-icon-ui
    [cartItemsCount]="numberOfBooksInCart$ | async"
    [animating]="animating$ | async"
    [openDropDown$]="isDropDownVisible$"
    (onIconClick)="iconClicked()"></shopping-cart-icon-ui>`,
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class ShoppingCartIconComponent {
  numberOfBooksInCart$: Observable<number>
  isDropDownVisible$: Observable<boolean>
  animating$: Observable<boolean>

  constructor(
    private store: Store<any>
  ) {
    this.numberOfBooksInCart$ = store.pipe(select(selectCartStatusBooksCount))
    this.animating$ = store.pipe(select(selectCartIconAnimatingStatus))
    this.isDropDownVisible$ = store.pipe(select(selectCartIconDropDownIsVisible))
  }

  iconClicked() {
    this.store.dispatch(toggleCartIconDropDown())
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""