What I'm trying to do is like this.
export class TestModel {
item1: {title: 'specific title', content: string};
item2: {title: 'specific title', content: string};
}
declare the object {title:string, value:string}, and initialize only title.
value of the content will be added after it declared.
but It didn't worked. so I changed it to like this.
interface testInterface {
title: string;
content: string;
}
export class TestModel {
item1: testInterface ;
item2: testInterface ;
constructor() {
this.item1 = { title: 'specific titleA', content: '' };
this.item2 = { title: 'specific titleB', content: '' };
}
}
I want to initialize title without the constructor(), to reduce the amount of code.
(and if it is possible, initialize only the title, not the content).
I tried
item1: testInterface = { title = 'specific titleA, content = '' };
and it didn't worked too.
Is there any good solution?