import { Component } from '@angular/core';
import { Cake } from './model/cake';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
cake = Cake;
constructor() {
this.cake = new Cake('Black Forest', 'This is awasome cake', null, null, null);
}
}
this is error-
C:/xampp/htdocs/cakeshop/src/app/app.component.ts(14,5)中的错误: 类型“蛋糕”不能分配给类型“蛋糕类型”。属性 类型“蛋糕”中缺少“原型”。
蛋糕类属性
export interface Ingredient {
ingredient: string;
measure: string;
}
export interface Instruction {
instruction: string;
photo: string;
}
export class Cake {
public title: string;
public description: string;
public ingredient: Ingredient[];
public instruction: Instruction[];
public cover_photo: string;
constructor(t: string, d: string, ing: Ingredient[], ins: Instruction[], cp: string) {
this.title = t;
this.description = d;
this.ingredient = ing;
this.instruction = ins;
this.cover_photo = cp;
}
}
答案 0 :(得分:0)
尝试在此处更改此分配。
cake = Cake;
以下,声明类型。
public cake: Cake;