パラメータを使用してクラスの新規インスタンスを作成しようとするとこのエラーが発生しますが、パラメータを使用しない場合はうまく動作します。何が問題なの?ここでエラー:クラス名(??)のすべてのパラメータを解決できません
はここでクラス
export class Recipe {
public name: string;
public description: string;
public imageP: string;
constructor(name1: string, description1: string, imagePath1: string) {
this.name = name1;
this.description = description1;
this.imageP = imagePath1;
}
}
である代わりに、私はそれぞれrecipe.tsレシピ-list.component.tsでこれを行う場合、コンポーネント
import {Component, OnInit, Output} from '@angular/core';
import { Recipe } from '../recipe';
@Component({
selector: 'rb-recipes-list',
templateUrl: './recipes-list.component.html',
providers: [ Recipe ]
})
export class RecipesListComponent implements OnInit {
theRecipe: Recipe = new Recipe('New', 'blah blah blah', 'ddkkkiskxmdks');
recipe = this.theRecipe.name;
constructor() { }
ngOnInit() {
}
}
です:
export class Recipe {
public name: string = 'hello world';
public description: string = 'hello world';
public imageP: string = 'hello world';
}
import {Component, OnInit, Output} from '@angular/core';
import { Recipe } from '../recipe';
@Component({
selector: 'rb-recipes-list',
templateUrl: './recipes-list.component.html',
providers: [ Recipe ]
})
export class RecipesListComponent implements OnInit {
//recipes: Recipe[] = [];
theRecipe: Recipe = new Recipe()
recipe = this.theRecipe.name;
constructor() { }
ngOnInit() {
}
}
は完全に機能します。
なぜあなたはそれを使用しない場合、あなたは 'Recipe'クラスをプロバイダとして渡しますか? – yurzui
プロバイダに依存関係を注入する必要はありません。配列 –
@yurzui 8秒の違いで同じコメントを追加しました:p –