-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecipe-list.component.ts
37 lines (33 loc) · 1022 Bytes
/
recipe-list.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Recipe } from "../../models/recipe.model";
import { RecipeService } from "src/app/services/recipe.service";
import { Router, ActivatedRoute } from "@angular/router";
import { Subscription } from "rxjs";
@Component({
selector: "app-recipe-list",
templateUrl: "./recipe-list.component.html",
styleUrls: ["./recipe-list.component.css"]
})
export class RecipeListComponent implements OnInit, OnDestroy {
recipes: Recipe[];
subscription: Subscription;
constructor(
private recipeService: RecipeService,
private router: Router,
private route: ActivatedRoute
) {}
ngOnInit() {
this.recipes = this.recipeService.getRecipes();
this.subscription = this.recipeService.recipesChanged.subscribe(
(recipes: Recipe[]) => {
this.recipes = recipes;
}
);
}
onNewRecipe() {
this.router.navigate(["new"], { relativeTo: this.route });
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}