Answer the question
In order to leave comments, you need to log in
How to create an instance of a class that has properties - instances of another class?
Good afternoon!
There are two:
export class TestObject {
constructor(init?: Partial<TestObject>) {
Object.assign(this, init);
}
id: number;
name: string;
well: Well;
}
export class Well {
constructor(init?: Partial<Well>) {
Object.assign(this, init);
}
id: number;
name: string;
x: number;
y: number;
}
```
С бэкенда приходит объект
```
obj = {
id: 1,
name: 'first',
well: {
id: 2,
name: 'second',
x: 1,
y: 1
}
}
this.well = new Well(init.well);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question