|
|
|
@ -6,6 +6,7 @@ import { MatTableModule, MatTableDataSource } from '@angular/material/table';
|
|
|
|
|
import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
|
|
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
|
|
|
import { TruncatePipe } from '../pipes/truncate.pipe';
|
|
|
|
|
import { RecipeService } from '../services/recipe.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-recipe-list',
|
|
|
|
@ -27,10 +28,10 @@ export class RecipeListComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
@ViewChild(MatPaginator) paginator!: MatPaginator;
|
|
|
|
|
|
|
|
|
|
constructor(private router: Router) {}
|
|
|
|
|
constructor(private router: Router, private recipeService: RecipeService) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.recipes = JSON.parse(localStorage.getItem('recipes') || '[]');
|
|
|
|
|
this.recipes = this.recipeService.getRecipes();
|
|
|
|
|
this.dataSource.data = this.recipes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -45,4 +46,10 @@ export class RecipeListComponent implements OnInit {
|
|
|
|
|
onSelectRecipe(recipe: Recipe): void {
|
|
|
|
|
this.router.navigate(['/recipe', recipe.id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDeleteRecipe(recipe: Recipe): void {
|
|
|
|
|
this.recipeService.deleteRecipe(recipe.id);
|
|
|
|
|
this.recipes = this.recipeService.getRecipes();
|
|
|
|
|
this.dataSource.data = this.recipes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|