浏览代码

10-110 Passing ingredients from recipe to shopping list

tags/before_ngrx
Nils Dittberner 8 年前
父节点
当前提交
b495000a01
共有 5 个文件被更改,包括 36 次插入18 次删除
  1. +15
    -15
      package-lock.json
  2. +1
    -1
      package.json
  3. +6
    -1
      src/app/recipes/recipe-detail/recipe-detail.component.ts
  4. +9
    -1
      src/app/recipes/recipe.service.ts
  5. +5
    -0
      src/app/shopping-list/shopping-list.service.ts

+ 15
- 15
package-lock.json 查看文件

@@ -81,7 +81,7 @@
"memory-fs": "0.4.1",
"minimatch": "3.0.4",
"node-modules-path": "1.0.1",
"node-sass": "4.7.1",
"node-sass": "4.7.2",
"nopt": "4.0.1",
"opn": "5.1.0",
"portfinder": "1.0.13",
@@ -326,9 +326,9 @@
}
},
"ajv": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.3.0.tgz",
"integrity": "sha1-RBT/dKUIecII7l/cgm4ywwNUnto=",
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.4.0.tgz",
"integrity": "sha1-MtHPCNvIDEMvQm8S4QslEfa0ZHQ=",
"dev": true,
"requires": {
"co": "4.6.0",
@@ -587,7 +587,7 @@
"dev": true,
"requires": {
"browserslist": "1.7.7",
"caniuse-db": "1.0.30000766",
"caniuse-db": "1.0.30000769",
"normalize-range": "0.1.2",
"num2fraction": "1.2.2",
"postcss": "5.2.18",
@@ -1002,7 +1002,7 @@
"integrity": "sha1-C9dnBCWL6CmyOYu1Dkti0aFmsLk=",
"dev": true,
"requires": {
"caniuse-db": "1.0.30000766",
"caniuse-db": "1.0.30000769",
"electron-to-chromium": "1.3.27"
}
},
@@ -1107,15 +1107,15 @@
"dev": true,
"requires": {
"browserslist": "1.7.7",
"caniuse-db": "1.0.30000766",
"caniuse-db": "1.0.30000769",
"lodash.memoize": "4.1.2",
"lodash.uniq": "4.5.0"
}
},
"caniuse-db": {
"version": "1.0.30000766",
"resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000766.tgz",
"integrity": "sha1-TJEao3R/ATiEUvpLknt4/PFDBoA=",
"version": "1.0.30000769",
"resolved": "https://registry.npmjs.org/caniuse-db/-/caniuse-db-1.0.30000769.tgz",
"integrity": "sha1-wjC5wbno2z4cDYWMluaFdBuWzBA=",
"dev": true
},
"caseless": {
@@ -5315,9 +5315,9 @@
"dev": true
},
"node-sass": {
"version": "4.7.1",
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.1.tgz",
"integrity": "sha512-WUG10FNj6E3bXpAy7f3bXVdLVUJuNn8pRbT4oo5ez9Zp5ZfqPFKsVJuDEEUmkpdyGa8P9JwifEr5dhNgZT2FpQ==",
"version": "4.7.2",
"resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz",
"integrity": "sha512-CaV+wLqZ7//Jdom5aUFCpGNoECd7BbNhjuwdsX/LkXBrHl8eb1Wjw4HvWqcFvhr5KuNgAk8i/myf/MQ1YYeroA==",
"dev": true,
"optional": true,
"requires": {
@@ -7317,7 +7317,7 @@
"integrity": "sha1-9YdyIs4+kx7a4DnxfrNxbnE3+M8=",
"dev": true,
"requires": {
"ajv": "5.3.0"
"ajv": "5.4.0"
}
},
"scss-tokenizer": {
@@ -8741,7 +8741,7 @@
"requires": {
"acorn": "5.2.1",
"acorn-dynamic-import": "2.0.2",
"ajv": "5.3.0",
"ajv": "5.4.0",
"ajv-keywords": "2.1.1",
"async": "2.6.0",
"enhanced-resolve": "3.4.1",


+ 1
- 1
package.json 查看文件

@@ -27,7 +27,7 @@
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.5.2",
"@angular/cli": "^1.5.2",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",


+ 6
- 1
src/app/recipes/recipe-detail/recipe-detail.component.ts 查看文件

@@ -1,5 +1,6 @@
import { Component, OnInit, Input } from '@angular/core';
import { Recipe } from '../recipe.model';
import { RecipeService } from '../recipe.service';

@Component({
selector: 'app-recipe-detail',
@@ -9,9 +10,13 @@ import { Recipe } from '../recipe.model';
export class RecipeDetailComponent implements OnInit {
@Input() recipe: Recipe;
constructor() { }
constructor(private recipeService: RecipeService) { }

ngOnInit() {
}

onAddToShoppingList() {
this.recipeService.addIngredientsToShoppingList(this.recipe.ingredients);
}

}

+ 9
- 1
src/app/recipes/recipe.service.ts 查看文件

@@ -1,7 +1,9 @@
import { Recipe } from "./recipe.model";
import { EventEmitter } from "@angular/core";
import { EventEmitter, Injectable } from "@angular/core";
import { Ingredient } from "../shared/ingredient.model";
import { ShoppingListService } from "../shopping-list/shopping-list.service";

@Injectable()
export class RecipeService {
recipeSelected = new EventEmitter<Recipe>();

@@ -26,7 +28,13 @@ export class RecipeService {
)
];

constructor(private shoppingListService: ShoppingListService) { }

getRecipes() {
return this.recipes.slice();
}

addIngredientsToShoppingList(ingredients: Ingredient[]) {
this.shoppingListService.addIngredients(ingredients);
}
}

+ 5
- 0
src/app/shopping-list/shopping-list.service.ts 查看文件

@@ -16,4 +16,9 @@ export class ShoppingListService {
this.ingredients.push(ingredient);
this.ingredientsChanged.emit(this.ingredients.slice());
}

addIngredients(ingredients: Ingredient[]) {
this.ingredients.push(...ingredients);
this.ingredientsChanged.emit(this.ingredients.slice());
}
}

正在加载...
取消
保存