|
|
|
@@ -1,8 +1,9 @@ |
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core'; |
|
|
|
import { Router, ActivatedRoute } from '@angular/router'; |
|
|
|
|
|
|
|
import { Recipe } from '../recipe.model'; |
|
|
|
import { RecipeService } from '../recipe.service'; |
|
|
|
import { Subscription } from 'rxjs/Subscription'; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@@ -10,7 +11,8 @@ import { RecipeService } from '../recipe.service'; |
|
|
|
templateUrl: './recipe-list.component.html', |
|
|
|
styleUrls: ['./recipe-list.component.css'] |
|
|
|
}) |
|
|
|
export class RecipeListComponent implements OnInit { |
|
|
|
export class RecipeListComponent implements OnInit, OnDestroy { |
|
|
|
subscription: Subscription; |
|
|
|
recipes: Recipe[]; |
|
|
|
|
|
|
|
constructor(private recipeService: RecipeService, |
|
|
|
@@ -18,7 +20,7 @@ export class RecipeListComponent implements OnInit { |
|
|
|
private route: ActivatedRoute) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.recipeService.recipesChanged.subscribe( |
|
|
|
this.subscription = this.recipeService.recipesChanged.subscribe( |
|
|
|
(recipes: Recipe[]) => { |
|
|
|
this.recipes = recipes; |
|
|
|
} |
|
|
|
@@ -29,4 +31,8 @@ export class RecipeListComponent implements OnInit { |
|
|
|
onNewRecipe() { |
|
|
|
this.router.navigate(['new'], {relativeTo: this.route}); |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
|
this.subscription.unsubscribe(); |
|
|
|
} |
|
|
|
} |