我有一个基本的模型类(而不是组件):方法格式
export class catModel {
constructor(public name: string) { }
getName: string {
return this.name.toUpperCase();
}
}
现在,我会试着在这样的组件使用这个模型:
feline: catModel = {name: 'simba' };
...当我编译我得到以下错误:
Type '{ name: string }' is not assignable to type 'catModel'. Property 'getName' is missing in type '{ name: string }'
只要从catModel中删除getName函数它工作正常,wh你不会让我添加一个方法吗?
这样做,使用'新'解决了这个问题。 – Helzgate