You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
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. }