I have a class name “Person” and I want to create a custom object of class names “PersonDetails”. How can I achieve that with Angular. For example
export class Person {
name: string;
details: PersonDetails;
}
class PersonDetails {
age: number;
}
I think for data you would be fine with interfaces, and can be achieved in a couple of ways…
export interface Person{
name: string;
details: PersonDetails
}
export interface PersonDetails{
age: number;
}
or all in one…
export interface Person{
name: string;
details: {
age: number;
}
}
To instantiate one of these it’s pretty much like any javascript object but with typesafety…
let person: Person = {
name: 'Tom',
details: {
age: 40
}
}
Is that what you mean?