2017-07-28 56 views
-2

對象結構中使用符合通話對象的任何簽名看起來像如下:提供的參數不打字稿與角2

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

    constructorn(name: string, desc: string, imagePath: string) { 
     this.name = name; 
     this.description = desc; 
     this.imagePath = imagePath; 
    } 
} 

我的調用語句:

export class RecipeListComponent implements OnInit { 
    recipes: Recipe[] = [ 
     new Recipe('Test Recipe', 'This is simply a test', 
      'https://cdn.pixabay.com/photo/2016/06/15/19/09/food- 
      1459693_960_720.jpg') 
    ]; 

} 

雖然我通過了所有該參數,但我仍然收到錯誤「提供的參數不匹配呼叫目標的任何簽名」

+1

檢查你的拼寫。 – jonrsharpe

回答

2

拼寫錯誤constructor並可能想要使用參數屬性。

export class Recipe { 
    constructor(public name: string, public desc: string, public imagePath: string) { 
     // Insert logic.. 
    } 
} 

這應該做的工作。