diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-12-04 23:00:02 -0500 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-12-08 15:03:07 -0500 |
commit | 443ded565b1482eaf17176967372f3986497f1b8 (patch) | |
tree | 01301c9d7c79e0f161263c8a933cebbae7d14f4f /recipeBuddy/src/app/add-recipe/add-recipe.component.ts | |
parent | 651c877315b0669eeb4a3a8447691ae65accf20b (diff) |
Add basic form for adding a recipe
Diffstat (limited to 'recipeBuddy/src/app/add-recipe/add-recipe.component.ts')
-rw-r--r-- | recipeBuddy/src/app/add-recipe/add-recipe.component.ts | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts index a7be0e0..b0e5ce5 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts @@ -1,15 +1,68 @@ import { Component, OnInit } from '@angular/core'; +import { FormControl } from '@angular/forms'; + +import { FormBuilder } from '@angular/forms'; +import { FormArray } from '@angular/forms'; + @Component({ selector: 'app-add-recipe', templateUrl: './add-recipe.component.html', styleUrls: ['./add-recipe.component.css'] }) -export class AddRecipeComponent implements OnInit { - constructor() { } +export class AddRecipeComponent { + + recipeForm = this.fb.group({ + recipeName: [''], + desc: [''], + ingredients: this.fb.array([ + this.fb.group({ + ingrName: [''], + amount: [''], + units: [''] + }) + ]), + steps: this.fb.array([ + this.fb.group({ + instruct: [''], + timer: [''] + }) + ]), + servingSize: [''], + cookTime: [''], + tags: [''], + photos: [''] + }); + constructor(private fb: FormBuilder) { } ngOnInit() { } + get ingredients() { + return this.recipeForm.get('ingredients') as FormArray; + } + + addIngredient() { + this.ingredients.push( + this.fb.group({ + ingrName: [''], + amount: [''], + units: [''] + }) + ); + } + + get steps() { + return this.recipeForm.get('steps') as FormArray; + } + + addStep() { + this.steps.push( + this.fb.group({ + instruct: [''], + timer: [''] + }) + ); + } } |