Angular 问题:错误 TS2554:需要 0 个参数,但得到 3 个

Angular issue : error TS2554: Expected 0 arguments, but got 3

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

我的食谱模型 class 看起来像这样:

    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;
    }
}

这就是我的食谱列表-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 {
  }

}

This is how my app structure looks like.

任何人都可以建议我如何解决这个问题。 我正在使用 Angular CLI:10.0.5,节点:12.18.2.

您的食谱模型中有错字。

应该是constructor,不是constructor

是的,有错别字。在 Recipe 模型中,应该是 constructor 而不是 constructor。

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