|
|
|
@@ -1,5 +1,4 @@ |
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core'; |
|
|
|
import { Subscription } from 'rxjs/Subscription'; |
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { Observable } from 'rxjs/Observable'; |
|
|
|
|
|
|
|
@@ -11,27 +10,17 @@ import { ShoppingListService } from './shopping-list.service'; |
|
|
|
templateUrl: './shopping-list.component.html', |
|
|
|
styleUrls: ['./shopping-list.component.css'] |
|
|
|
}) |
|
|
|
export class ShoppingListComponent implements OnInit, OnDestroy { |
|
|
|
export class ShoppingListComponent implements OnInit { |
|
|
|
shoppingListState: Observable<{ingredients: Ingredient[]}>; |
|
|
|
private subscription: Subscription |
|
|
|
|
|
|
|
constructor(private shoppingListService: ShoppingListService, |
|
|
|
private store: Store<{shoppingList: {ingredients: Ingredient[]}}>) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.shoppingListState = this.store.select('shoppingList'); |
|
|
|
// this.subscription = this.shoppingListService.ingredientsChanged.subscribe( |
|
|
|
// (ingredients: Ingredient[]) => { |
|
|
|
// this.ingredients = ingredients; |
|
|
|
// } |
|
|
|
// ); |
|
|
|
} |
|
|
|
|
|
|
|
onEditItem(index: number) { |
|
|
|
this.shoppingListService.startedEditing.next(index); |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
|
this.subscription.unsubscribe(); |
|
|
|
} |
|
|
|
} |