Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

24 rader
768 B

  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http'
  3. import { RecipeService } from '../recipes/recipe.service';
  4. import { Recipe } from '../recipes/recipe.model';
  5. @Injectable()
  6. export class DataStorageService {
  7. readonly baseUrl: string = 'https://my-recipe-book-cb837.firebaseio.com/';
  8. constructor(private httpClient: HttpClient, private recipeService: RecipeService) {}
  9. storeRecipes() {
  10. return this.httpClient.put(this.baseUrl + 'recipes.json', this.recipeService.getRecipes());
  11. }
  12. fetchRecipes() {
  13. this.httpClient.get<Recipe[]>(this.baseUrl + 'recipes.json').subscribe(
  14. recipes => {
  15. this.recipeService.replaceRecipes(recipes);
  16. }
  17. )
  18. }
  19. }