diff --git a/src/app/recipes/recipe-detail/recipe-detail.component.html b/src/app/recipes/recipe-detail/recipe-detail.component.html
index 61b650e..ea90ff7 100644
--- a/src/app/recipes/recipe-detail/recipe-detail.component.html
+++ b/src/app/recipes/recipe-detail/recipe-detail.component.html
@@ -19,7 +19,7 @@
diff --git a/src/app/recipes/recipe-detail/recipe-detail.component.ts b/src/app/recipes/recipe-detail/recipe-detail.component.ts
index 65a82c3..2239be4 100644
--- a/src/app/recipes/recipe-detail/recipe-detail.component.ts
+++ b/src/app/recipes/recipe-detail/recipe-detail.component.ts
@@ -33,4 +33,9 @@ export class RecipeDetailComponent implements OnInit {
onEditRecipe() {
this.router.navigate(['edit'], {relativeTo: this.route});
}
+
+ onDelete() {
+ this.recipeService.delteRecipe(this.id);
+ this.router.navigate(['/recipes']);
+ }
}
diff --git a/src/app/recipes/recipe-edit/recipe-edit.component.html b/src/app/recipes/recipe-edit/recipe-edit.component.html
index 56ed7d9..f03899f 100644
--- a/src/app/recipes/recipe-edit/recipe-edit.component.html
+++ b/src/app/recipes/recipe-edit/recipe-edit.component.html
@@ -4,7 +4,7 @@
@@ -29,14 +29,15 @@
name="imagePath"
id="imagePath"
formControlName="imagePath"
- class="form-control">
+ class="form-control"
+ #imagePath>
diff --git a/src/app/recipes/recipe-edit/recipe-edit.component.ts b/src/app/recipes/recipe-edit/recipe-edit.component.ts
index 7c2a506..7bab17c 100644
--- a/src/app/recipes/recipe-edit/recipe-edit.component.ts
+++ b/src/app/recipes/recipe-edit/recipe-edit.component.ts
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
-import { ActivatedRoute, Params } from '@angular/router';
+import { ActivatedRoute, Params, Router } from '@angular/router';
import { FormArray, FormGroup, FormControl, Validators } from '@angular/forms';
+
import { RecipeService } from '../recipe.service';
-import { Recipe } from '../recipe.model';
@Component({
selector: 'app-recipe-edit',
@@ -15,7 +15,8 @@ export class RecipeEditComponent implements OnInit {
recipeForm: FormGroup
constructor(private route: ActivatedRoute,
- private recipeService: RecipeService) { }
+ private recipeService: RecipeService,
+ private router: Router) { }
ngOnInit() {
this.route.params.subscribe(
@@ -37,6 +38,7 @@ export class RecipeEditComponent implements OnInit {
} else {
this.recipeService.addRecipe(this.recipeForm.value);
}
+ this.router.navigate(['../'], {relativeTo: this.route});
}
onAddIngredient() {
@@ -48,6 +50,10 @@ export class RecipeEditComponent implements OnInit {
)
}
+ onCandel() {
+ this.router.navigate(['../'], {relativeTo: this.route});
+ }
+
private initForm() {
let recipeName = '';
let recipeImagePath = '';
diff --git a/src/app/recipes/recipe.service.ts b/src/app/recipes/recipe.service.ts
index c5304a5..c9c8283 100644
--- a/src/app/recipes/recipe.service.ts
+++ b/src/app/recipes/recipe.service.ts
@@ -51,4 +51,9 @@ export class RecipeService {
this.recipes[index] = newRecipe;
this.recipesChanged.next(this.recipes.slice());
}
+
+ delteRecipe(index: number) {
+ this.recipes.splice(index, 1);
+ this.recipesChanged.next(this.recipes.slice());
+ }
}
\ No newline at end of file