looking for some solutions? You are welcome.

SOLVED: Type 'void' is not assignable to type 'Recipe[]'. error in this line of code this: recipes = this.recipeService.getRecipes();

ALEX:
import { Component, OnInit } from '@angular/core';

import { RecipeService } from '../recipe.service';

import { Recipe } from '../recipe.model';

@Component({

selector: 'app-recipe-list',

templateUrl: './recipe-list.component.html'

})


export class RecipeListComponent implements OnInit {

  recipes: Recipe[];

  constructor(private recipeService: RecipeService) {
  }

  ngOnInit() {

    this.recipes = this.recipeService.getRecipes();

  }
}





import { Recipe } from './recipe.model';

import { EventEmitter } from '@angular/core';


export class RecipeService {

  recipeSelect = new EventEmitter<Recipe>();

   private recipes: Recipe[] = [

        new Recipe('A Test Recipe', 'This is simply a test', 'https://upload.wikimedia.org/wikipedia/commons/1/15/Recipe_logo.jpeg'),

        new Recipe('Another Test Recipe', 'This is simply a test', 'https://upload.wikimedia.org/wikipedia/commons/1/15/Recipe_logo.jpeg')

 ];

getRecipes() {

this.recipes.slice();

}

}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent