commit
9d52ef64cc
@ -0,0 +1,7 @@
|
||||
#page-wrapper {
|
||||
width: 70%;
|
||||
border: 3px solid black;
|
||||
|
||||
margin: 1rem auto;
|
||||
padding: 1rem;
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { provideRouter, withComponentInputBinding } from '@angular/router';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideRouter(routes)]
|
||||
providers: [
|
||||
provideRouter(routes, withComponentInputBinding()),
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,14 @@
|
||||
import { Routes } from '@angular/router'
|
||||
|
||||
import { RecipeFormComponent } from "./recipe-form/recipe-form.component";
|
||||
import { Error404Component } from "./components/errors/errors.component";
|
||||
import { RecipeFormComponent } from "./components/recipe-form/recipe-form.component";
|
||||
import { RecipeListComponent } from "./components/recipe-list/recipe-list.component";
|
||||
import { RecipeDetailComponent } from './components/recipe-detail/recipe-detail.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: 'add', component: RecipeFormComponent },
|
||||
{ path: '', component: RecipeListComponent }
|
||||
{ path: '', component: RecipeListComponent },
|
||||
{ path: 'error/:status', component: Error404Component},
|
||||
|
||||
{ path: 'recipe/add', component: RecipeFormComponent },
|
||||
{ path: 'recipe/:id', component: RecipeDetailComponent },
|
||||
];
|
||||
|
@ -0,0 +1 @@
|
||||
<h1>{{ status }}</h1>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { Error404Component } from './error404.component';
|
||||
|
||||
describe('Error404Component', () => {
|
||||
let component: Error404Component;
|
||||
let fixture: ComponentFixture<Error404Component>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Error404Component]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(Error404Component);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-errors',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './errors.component.html',
|
||||
styleUrl: './errors.component.css'
|
||||
})
|
||||
export class Error404Component {
|
||||
status: string | null = "Unknown error";
|
||||
|
||||
constructor(private route: ActivatedRoute){}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.paramMap.subscribe(params => {
|
||||
this.status = params.get('status');
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
img {
|
||||
max-height: 300px;
|
||||
height: 300px;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<div id="recipe-detail">
|
||||
<img src="{{ recipe.image }}" />
|
||||
<h1>{{ recipe.name }}</h1>
|
||||
<p>{{ recipe.description }}</p>
|
||||
|
||||
<h2>Ingredients</h2>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RecipeDetailComponent } from './recipe-detail.component';
|
||||
|
||||
describe('RecipeDetailComponent', () => {
|
||||
let component: RecipeDetailComponent;
|
||||
let fixture: ComponentFixture<RecipeDetailComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [RecipeDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(RecipeDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,34 @@
|
||||
import { Component} from '@angular/core';
|
||||
import { Recipe } from '../../model/recipe.model';
|
||||
import { RecipeService } from '../../services/recipe.service';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-detail',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './recipe-detail.component.html',
|
||||
styleUrl: './recipe-detail.component.css'
|
||||
})
|
||||
export class RecipeDetailComponent {
|
||||
|
||||
recipe!: Recipe;
|
||||
id: string | null = null;
|
||||
|
||||
constructor(private router: Router, private route: ActivatedRoute, private recipeService: RecipeService) {
|
||||
this.recipeService.getRecipes();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.paramMap.subscribe(params => {
|
||||
this.id = params.get('id');
|
||||
if (this.id) {
|
||||
this.recipe = this.recipeService.getRecipeById(Number(this.id))!;
|
||||
}
|
||||
if (this.recipe === undefined) {
|
||||
this.router.navigate(['/error/404'])
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<h2>New Recipe</h2>
|
||||
<h1>New Recipe</h1>
|
||||
<form [formGroup]="recipeForm" (ngSubmit)="onSubmit()">
|
||||
<label for="name">Name:</label>
|
||||
<input id="name" formControlName="name">
|
@ -1,10 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { Recipe } from '../model/recipe.model';
|
||||
import { Ingredient } from '../model/ingredient.model';
|
||||
import { Recipe } from '../../model/recipe.model';
|
||||
import { Ingredient } from '../../model/ingredient.model';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { RecipeService } from '../services/recipe.service';
|
||||
import { RecipeService } from '../../services/recipe.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-recipe-form',
|
@ -1,5 +1,6 @@
|
||||
#recipe-list {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 2rem;
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
<h1>Recipe List</h1>
|
||||
|
||||
<div id="recipe-list">
|
||||
<app-recipe-mini *ngFor="let recipe of recipes" [recipe]="recipe"></app-recipe-mini>
|
||||
</div>
|
Loading…
Reference in new issue