【问题标题】:Angular issue : error TS2554: Expected 0 arguments, but got 3 [closed]角度问题:错误 TS2554:预期 0 个参数,但得到 3 个 [关闭]
【发布时间】:2020-11-22 22:39:15
【问题描述】:

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

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

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

}

This is how my app structure looks like.

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

【问题讨论】:

    标签: angular typescript angular10


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您的配方模型中有错字。

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

      【讨论】:

      • 谢谢你,Subham
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 2021-08-22
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多