|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import { Component, EventEmitter, Output } from '@angular/core';
|
|
|
|
|
import { Recipe } from "../../model/recipe.model";
|
|
|
|
|
import {FormControl, FormGroup, ReactiveFormsModule, FormArray, FormBuilder} from "@angular/forms";
|
|
|
|
|
import { FormControl, FormGroup, ReactiveFormsModule, FormArray, FormBuilder, Validators } from "@angular/forms";
|
|
|
|
|
import { Ingredient } from '../../model/ingredient.model';
|
|
|
|
|
import { Unity } from '../../model/unity';
|
|
|
|
|
import { IngredientService } from '../../service/ingredient.service';
|
|
|
|
@ -10,8 +10,7 @@ import {NgFor, NgIf} from "@angular/common";
|
|
|
|
|
selector: 'app-recipe-form',
|
|
|
|
|
standalone: true,
|
|
|
|
|
imports: [ReactiveFormsModule, NgFor, NgIf],
|
|
|
|
|
templateUrl: './recipe-form.component.html',
|
|
|
|
|
styleUrl: './recipe-form.component.css'
|
|
|
|
|
templateUrl: './recipe-form.component.html'
|
|
|
|
|
})
|
|
|
|
|
export class RecipeFormComponent {
|
|
|
|
|
@Output() formSubmitted = new EventEmitter<Recipe>();
|
|
|
|
@ -29,9 +28,9 @@ export class RecipeFormComponent {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recipeForm: FormGroup = this.formBuilder.group({
|
|
|
|
|
id: new FormControl('', { nonNullable: true }),
|
|
|
|
|
name: new FormControl('', { nonNullable: true }),
|
|
|
|
|
description: new FormControl('', { nonNullable: true }),
|
|
|
|
|
id: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
|
|
|
|
|
name: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
|
|
|
|
|
description: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
|
|
|
|
|
ingredients: this.formBuilder.array([this.newIngredient()]),
|
|
|
|
|
image: new FormControl('', {nonNullable: false})
|
|
|
|
|
});
|
|
|
|
@ -42,15 +41,16 @@ export class RecipeFormComponent {
|
|
|
|
|
|
|
|
|
|
newIngredient(): FormGroup {
|
|
|
|
|
return this.formBuilder.group({
|
|
|
|
|
quantity: new FormControl(0, { nonNullable: true }),
|
|
|
|
|
unit: new FormControl('', { nonNullable: true }),
|
|
|
|
|
ingredient: new FormControl('', { nonNullable: true })
|
|
|
|
|
quantity: new FormControl(0, { nonNullable: true, validators: [Validators.required] }),
|
|
|
|
|
unit: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
|
|
|
|
|
ingredient: new FormControl('', { nonNullable: true, validators: [Validators.required] })
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addIngredient() {
|
|
|
|
|
this.ingredients.push(this.newIngredient());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeIngredient(index: number) {
|
|
|
|
|
if (this.ingredients.length > 1) {
|
|
|
|
|
|
|
|
|
@ -92,8 +92,5 @@ export class RecipeFormComponent {
|
|
|
|
|
this.ingredients.clear()
|
|
|
|
|
this.addIngredient()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|