|
|
|
@ -23,6 +23,10 @@ export class RecipeAddComponent {
|
|
|
|
|
ingredientEntries: IngredientEntry[] = [];
|
|
|
|
|
ingredients: Ingredient[] = [];
|
|
|
|
|
|
|
|
|
|
getIngredient(n: number): Ingredient {
|
|
|
|
|
return this.ingredients.find(v => v.id === n)!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#recipeId: number = -1;
|
|
|
|
|
@Input()
|
|
|
|
|
set recipeId(recipeId: string) {
|
|
|
|
@ -41,7 +45,6 @@ export class RecipeAddComponent {
|
|
|
|
|
|
|
|
|
|
constructor(private formBuilder: FormBuilder, private recipes: RecipeService, private router: Router) {
|
|
|
|
|
this.ingredients = this.recipes.getAllIngredients();
|
|
|
|
|
console.log(this.ingredients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSubmit(): void {
|
|
|
|
@ -65,13 +68,19 @@ export class RecipeAddComponent {
|
|
|
|
|
|
|
|
|
|
onAddIngredient(): void {
|
|
|
|
|
const value = this.createForm.value;
|
|
|
|
|
console.log(value);
|
|
|
|
|
|
|
|
|
|
if (!value.selectedIngredient) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const id = parseInt(value.selectedIngredient!);
|
|
|
|
|
if (this.ingredientEntries.find((ingredient) => ingredient.idIngredient === id)) {
|
|
|
|
|
console.log("oh");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("ah");
|
|
|
|
|
console.log(this.ingredients.find(v => v.id === id)?.name)
|
|
|
|
|
console.log(this.ingredients);
|
|
|
|
|
this.ingredientEntries.push({
|
|
|
|
|
idIngredient: id,
|
|
|
|
|
idRecipe: -1,
|
|
|
|
|