我想用Angular2在Webstorm上编写一个Web应用程序.我很擅长这样做.我正在尝试角度网站 Angular.IO上的教程. 当我尝试列出Person可点击的列表时,它不起作用. export class PersonComponent { persons = MYP
当我尝试列出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;
}
我收到以下错误:
Type ‘Person’ is not assignable to type ‘typeof Person’.
Property ‘prototype’ is missing in type ‘Person’.
这是什么意思?我在互联网上找不到这个错误.由于我的经验不足,这可能是我在代码上看不到的任何内容
当你这样写:selectedPersons = Person;
您正在为变量selectedPersons赋予类Person引用的默认值.您可能打算做的是指定selectedPersons类属性将包含Person类实例.你可以这样做:
selectedPersons:Person;
