-3

我知道构造函数或类存在一些问题,但我不确定是什么问题。

我的食谱模型类如下所示:

    export class Recipe{
    public name : string;
    public description :string;
    public imagePath : string;

    contructor(name : string , desc : string , imagePath :string){

        this.name = name;
        this.description = desc;
        this.imagePath = imagePath;
    }
}

这就是我的 recipe-list-component.ts ,

import { Component, OnInit } from '@angular/core';
import { Recipe } from '../recipe.model';

@Component({
  selector: 'app-recipe-list',
  templateUrl: './recipe-list.component.html',
  styleUrls: ['./recipe-list.component.css']
})
export class RecipeListComponent implements OnInit {

  recipes : Recipe[] = [
    new Recipe('A Test Recipe' , 'This is test' , 'abc.jsp')];
  
  constructor() { }

  ngOnInit(): void {
  }

}

这就是我的应用程序结构的样子。

谁能建议我如何解决这个问题。我正在使用 Angular CLI:10.0.5,节点:12.18.2。

4

2 回答 2

2

您的食谱模型中有错字。

它应该是构造函数,而不是构造函数。

于 2020-08-02T18:53:28.290 回答
0

是的,有一个拼写错误。在Recipe模型中,它应该是构造函数而不是构造函数。

请使用 Visual Studio 代码 IDE。这将突出显示代码中的错误。

于 2020-08-02T19:05:59.223 回答