* I really dont know and dont understand why this is happening, im new using Angular *
ErrorSubsequent property declarations must have the same type. Property 'post1' must be of type 'Posts', but here has type 'any' and Duplicate identifier 'post1'
Post class
export class Posts{
Key:string;
Email:string;
Password:string;
}
AppComponent class where i use the post class
export class AppComponent {
title = 'proyecto-nro2';
post1 = new Posts();
//Said the error above in every post1.
post1.Key = 'NONE';
post1.Email = 'NONE';
post1.Password = '2';
}
Properties can't initialised directly on a class in ES6. Initialise the post object inside the constructor and set the properties.
export class AppComponent {
title = 'proyecto-nro2';
post1: Posts;
constructor(){
this.post1 = new Posts();
this.post1.Key = 'NONE';
this.post1.Email = 'NONE';
this.post1.Password = '2';
}
}
Other Option:
class Posts {
Key: string;
Email: string;
Password: string;
constructor(key: string, email: string, password: string) {
this.Key = key;
this.Email = email;
this.Password = password;
}
}
export class AppComponent {
title = 'proyecto-nro2';
post1: Posts = new Posts('NONE', 'NONE', '2');
}
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