|
|
|
@@ -1,5 +1,6 @@ |
|
|
|
import { Component, OnInit, ViewChild, ElementRef, EventEmitter, Output } from '@angular/core'; |
|
|
|
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; |
|
|
|
import { Ingredient } from '../../shared/ingredient.model'; |
|
|
|
import { ShoppingListService } from '../shopping-list.service'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-shopping-edit', |
|
|
|
@@ -9,9 +10,8 @@ import { Ingredient } from '../../shared/ingredient.model'; |
|
|
|
export class ShoppingEditComponent implements OnInit { |
|
|
|
@ViewChild('nameInput') nameInputRef: ElementRef; |
|
|
|
@ViewChild('amountInput') amountInputRef: ElementRef; |
|
|
|
@Output() ingredientAdded = new EventEmitter<Ingredient>(); |
|
|
|
|
|
|
|
constructor() { } |
|
|
|
constructor(private shoppingListService: ShoppingListService) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
} |
|
|
|
@@ -19,6 +19,6 @@ export class ShoppingEditComponent implements OnInit { |
|
|
|
onAddItem() { |
|
|
|
const newIngredient = new Ingredient(this.nameInputRef.nativeElement.value, |
|
|
|
this.amountInputRef.nativeElement.value); |
|
|
|
this.ingredientAdded.emit(newIngredient); |
|
|
|
this.shoppingListService.addIngredient(newIngredient); |
|
|
|
} |
|
|
|
} |