'MyObject'类型中缺少属性'prototype'

TYL*_*TYL 11 typescript

我想用Angular2在Webstorm上编写一个Web应用程序.我很擅长这样做.我正在尝试角度网站Angular.IO上的教程.

当我尝试列出Person可点击的列表时,它不起作用.

export class PersonComponent {
 persons = MYPERSONS;
 selectedPersons = Person;

 onSelect(person: Person): void {
  this.selectedPerson = person;   // here is the error on "this.selectedPerson"
 }
}

const MYPERSONS: Person[] = [
 {id:0, firstName: 'First', lastName: 'Firstly', creationData: 1},
 {id:1, firstName: 'Second', lastName: 'Test', creationData:10},
 {id:2, firstName: 'Third', lastName: 'Candidate', creationData:5}
];

export class Person {
 id: number;
 firstName: string;
 lastName: string;
 creationData: any;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

类型'Person'不能分配给'typeof Person'."人物"类型中缺少属性"原型".

这是什么意思?我在互联网上找不到这个错误.由于我的经验不足,这可能是我在代码上看不到的任何内容

Max*_*kyi 31

当你这样写:

selectedPersons = Person;
Run Code Online (Sandbox Code Playgroud)

您正在为变量分配类Person 引用的默认值selectedPersons.您可能打算做的是指定selectedPersonsclass属性将包含一个 Person类实例.你可以这样做:

selectedPersons:Person;
Run Code Online (Sandbox Code Playgroud)

  • 天啊!谢谢.真是太微不足道了! (2认同)
  • 如果您有上述错误,请检查=和: (2认同)