File

libs/fruit-basket/src/basket-ui/basket-ui.component.ts

Metadata

selector basket-ui
templateUrl ./basket-ui.component.html

Index

Properties
Methods

Constructor

constructor(store: Store)
Parameters :
Name Type Optional
store Store<AppState> no

Methods

empty
empty()
Returns : void
pickApple
pickApple(count: number)
Parameters :
Name Type Optional
count number no
Returns : void
pickBerry
pickBerry()
Returns : void

Properties

apple
apple: Observable<number>
Type : Observable<number>
berry
berry: Observable<number>
Type : Observable<number>
Public store
store: Store<AppState>
Type : Store<AppState>
total
total: Observable<number>
Type : Observable<number>
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';

import { PickBerryAction, AppState, PickApplesAction, EmptyCartAction } from '../state/state';

@Component({
  selector: 'basket-ui',
  templateUrl: './basket-ui.component.html'
})
export class BasketUiComponent {
  berry: Observable<number>;
  apple: Observable<number>;
  total: Observable<number>;

  constructor(public store: Store<AppState>) {
    this.berry = store.select(state => state.fruit.berryCounter);
    this.apple = store.select(state => state.fruit.appleCounter);
    this.total = store.select(state => state.fruit.berryCounter + state.fruit.appleCounter);
  }

  pickBerry() {
    this.store.dispatch(new PickBerryAction());
  }

  pickApple(count: number) {
    this.store.dispatch(new PickApplesAction(count));
  }

  empty() {
    this.store.dispatch(new EmptyCartAction());
  }
}
<h3>Fruit Basket</h3>

<button (click)="empty()" class="btn">Empty Cart</button>
<p>Total Fruit: {{ total | async }}</p>

<div class="row">
  <counter-display
    class="col s12 m6"
    label="Berries"
    [counter]="berry | async"
    (pick)="pickBerry()">
  </counter-display>

  <counter-display
    class="col s12 m6"
    label="Apples"
    [counter]="apple | async"
    (pick)="pickApple($event)">
  </counter-display>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""