From 71e353d9c01bb061aa1fdeae1032336d94970cfc Mon Sep 17 00:00:00 2001 From: Nils Dittberner Date: Tue, 21 Nov 2017 11:26:09 +0100 Subject: [PATCH] 06-80 Adding ingredients --- .../shopping-edit/shopping-edit.component.html | 14 +++++++++++--- .../shopping-list/shopping-edit/shopping-edit.component.ts | 11 ++++++++++- src/app/shopping-list/shopping-list.component.html | 3 ++- src/app/shopping-list/shopping-list.component.ts | 4 ++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/app/shopping-list/shopping-edit/shopping-edit.component.html b/src/app/shopping-list/shopping-edit/shopping-edit.component.html index 6326370..ff9c298 100644 --- a/src/app/shopping-list/shopping-edit/shopping-edit.component.html +++ b/src/app/shopping-list/shopping-edit/shopping-edit.component.html @@ -4,16 +4,24 @@
- +
- +
- +
diff --git a/src/app/shopping-list/shopping-edit/shopping-edit.component.ts b/src/app/shopping-list/shopping-edit/shopping-edit.component.ts index 19edfff..de8994b 100644 --- a/src/app/shopping-list/shopping-edit/shopping-edit.component.ts +++ b/src/app/shopping-list/shopping-edit/shopping-edit.component.ts @@ -1,4 +1,5 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild, ElementRef, EventEmitter, Output } from '@angular/core'; +import { Ingredient } from '../../shared/ingredient.model'; @Component({ selector: 'app-shopping-edit', @@ -6,10 +7,18 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./shopping-edit.component.css'] }) export class ShoppingEditComponent implements OnInit { + @ViewChild('nameInput') nameInputRef: ElementRef; + @ViewChild('amountInput') amountInputRef: ElementRef; + @Output() ingredientAdded = new EventEmitter(); constructor() { } ngOnInit() { } + onAddItem() { + const newIngredient = new Ingredient(this.nameInputRef.nativeElement.value, + this.amountInputRef.nativeElement.value); + this.ingredientAdded.emit(newIngredient); + } } diff --git a/src/app/shopping-list/shopping-list.component.html b/src/app/shopping-list/shopping-list.component.html index 78ab2f9..c2cc788 100644 --- a/src/app/shopping-list/shopping-list.component.html +++ b/src/app/shopping-list/shopping-list.component.html @@ -1,6 +1,7 @@
- +