| @@ -5,12 +5,15 @@ import { RecipesComponent } from './recipes/recipes.component'; | |||||
| import { ShoppingListComponent } from './shopping-list/shopping-list.component'; | import { ShoppingListComponent } from './shopping-list/shopping-list.component'; | ||||
| import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component'; | import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component'; | ||||
| import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component'; | import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component'; | ||||
| import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component'; | |||||
| const appRoutes: Routes = [ | const appRoutes: Routes = [ | ||||
| { path: '', redirectTo: '/recipes', pathMatch: 'full' }, | { path: '', redirectTo: '/recipes', pathMatch: 'full' }, | ||||
| { path: 'recipes' , component: RecipesComponent, children: [ | { path: 'recipes' , component: RecipesComponent, children: [ | ||||
| { path: '', component: RecipeStartComponent }, | { path: '', component: RecipeStartComponent }, | ||||
| { path: ':id', component: RecipeDetailComponent } | |||||
| { path: 'new', component: RecipeEditComponent }, | |||||
| { path: ':id', component: RecipeDetailComponent }, | |||||
| { path: ':id/edit', component: RecipeEditComponent} | |||||
| ] }, | ] }, | ||||
| { path: 'shopping-list', component: ShoppingListComponent } | { path: 'shopping-list', component: ShoppingListComponent } | ||||
| ]; | ]; | ||||
| @@ -16,6 +16,7 @@ import { DropdownDirective } from './shared/dropdown.directive'; | |||||
| import { ShoppingListService } from './shopping-list/shopping-list.service'; | import { ShoppingListService } from './shopping-list/shopping-list.service'; | ||||
| import { AppRoutingModule } from './app-routing.module'; | import { AppRoutingModule } from './app-routing.module'; | ||||
| import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component'; | import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component'; | ||||
| import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component'; | |||||
| @NgModule({ | @NgModule({ | ||||
| @@ -29,7 +30,8 @@ import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.compon | |||||
| ShoppingListComponent, | ShoppingListComponent, | ||||
| ShoppingEditComponent, | ShoppingEditComponent, | ||||
| DropdownDirective, | DropdownDirective, | ||||
| RecipeStartComponent | |||||
| RecipeStartComponent, | |||||
| RecipeEditComponent | |||||
| ], | ], | ||||
| imports: [ | imports: [ | ||||
| BrowserModule, | BrowserModule, | ||||
| @@ -18,7 +18,7 @@ | |||||
| </button> | </button> | ||||
| <ul class="dropdown-menu"> | <ul class="dropdown-menu"> | ||||
| <li><a (click)="onAddToShoppingList()" style="cursor: pointer;">Add Ingredients</a></li> | <li><a (click)="onAddToShoppingList()" style="cursor: pointer;">Add Ingredients</a></li> | ||||
| <li><a style="cursor: pointer;">Edit Recipe</a></li> | |||||
| <li><a style="cursor: pointer;" (click)="onEditRecipe()">Edit Recipe</a></li> | |||||
| <li><a style="cursor: pointer;">Delete Recipe</a></li> | <li><a style="cursor: pointer;">Delete Recipe</a></li> | ||||
| </ul> | </ul> | ||||
| </div> | </div> | ||||
| @@ -1,7 +1,8 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { Router, ActivatedRoute, Params } from '@angular/router'; | |||||
| import { Recipe } from '../recipe.model'; | import { Recipe } from '../recipe.model'; | ||||
| import { RecipeService } from '../recipe.service'; | import { RecipeService } from '../recipe.service'; | ||||
| import { ActivatedRoute, Params } from '@angular/router'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipe-detail', | selector: 'app-recipe-detail', | ||||
| @@ -13,7 +14,8 @@ export class RecipeDetailComponent implements OnInit { | |||||
| id: number; | id: number; | ||||
| constructor(private recipeService: RecipeService, | constructor(private recipeService: RecipeService, | ||||
| private route: ActivatedRoute) { } | |||||
| private route: ActivatedRoute, | |||||
| private router: Router) { } | |||||
| ngOnInit() { | ngOnInit() { | ||||
| this.route.params.subscribe( | this.route.params.subscribe( | ||||
| @@ -28,4 +30,7 @@ export class RecipeDetailComponent implements OnInit { | |||||
| this.recipeService.addIngredientsToShoppingList(this.recipe.ingredients); | this.recipeService.addIngredientsToShoppingList(this.recipe.ingredients); | ||||
| } | } | ||||
| onEditRecipe() { | |||||
| this.router.navigate(['edit'], {relativeTo: this.route}); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,3 @@ | |||||
| <p> | |||||
| recipe-edit works! | |||||
| </p> | |||||
| @@ -0,0 +1,24 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | |||||
| import { ActivatedRoute, Params } from '@angular/router'; | |||||
| @Component({ | |||||
| selector: 'app-recipe-edit', | |||||
| templateUrl: './recipe-edit.component.html', | |||||
| styleUrls: ['./recipe-edit.component.css'] | |||||
| }) | |||||
| export class RecipeEditComponent implements OnInit { | |||||
| id: number; | |||||
| editMode: boolean = false; | |||||
| constructor(private route: ActivatedRoute) { } | |||||
| ngOnInit() { | |||||
| this.route.params.subscribe( | |||||
| (params: Params) => { | |||||
| this.id = +params['id']; | |||||
| this.editMode = params['id'] != null; | |||||
| } | |||||
| ); | |||||
| } | |||||
| } | |||||
| @@ -1,6 +1,6 @@ | |||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col-xs-12"> | <div class="col-xs-12"> | ||||
| <button class="btn btn-success">New Recipe</button> | |||||
| <button class="btn btn-success" (click)="onNewRecipe()">New Recipe</button> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <hr> | <hr> | ||||
| @@ -1,7 +1,10 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { Router, ActivatedRoute } from '@angular/router'; | |||||
| import { Recipe } from '../recipe.model'; | import { Recipe } from '../recipe.model'; | ||||
| import { RecipeService } from '../recipe.service'; | import { RecipeService } from '../recipe.service'; | ||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipe-list', | selector: 'app-recipe-list', | ||||
| templateUrl: './recipe-list.component.html', | templateUrl: './recipe-list.component.html', | ||||
| @@ -10,9 +13,15 @@ import { RecipeService } from '../recipe.service'; | |||||
| export class RecipeListComponent implements OnInit { | export class RecipeListComponent implements OnInit { | ||||
| recipes: Recipe[]; | recipes: Recipe[]; | ||||
| constructor(private recipeService: RecipeService) { } | |||||
| constructor(private recipeService: RecipeService, | |||||
| private router: Router, | |||||
| private route: ActivatedRoute) { } | |||||
| ngOnInit() { | ngOnInit() { | ||||
| this.recipes = this.recipeService.getRecipes(); | this.recipes = this.recipeService.getRecipes(); | ||||
| } | } | ||||
| onNewRecipe() { | |||||
| this.router.navigate(['new'], {relativeTo: this.route}); | |||||
| } | |||||
| } | } | ||||