I want to write a web-application on Webstorm with Angular2. I am very new on do this. I am trying the tutorial on the angular website Angular.IO.
When I try to make a list of Person clickable, it is not working.
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;
}
I get the following error:
Type 'Person' is not assignable to type 'typeof Person'. Property 'prototype' is missing in type 'Person'.
What does it mean? I can't find this error on the internet. It is probably anything what I'm not seeing on the code because of my few experience
When you write like this:
selectedPersons = Person;
you're assigning a default value of a class Person reference to the variable selectedPersons
. What you're probably intending to do is to specify that selectedPersons
class property will hold a Person
class instance. You can do it like this:
selectedPersons:Person;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With