Dinesh Dabhi
Dinesh Dabhi

Reputation: 856

How to define model with complex json structure in angular2 [typescript]?

I have one model with following properties

{
   Name:String,
   Id:Number,
   Store:{
      Name:String,
      City:String,
      State:String
   }
}

How can I define model with this structure in angular2 with typescript ?

Upvotes: 0

Views: 402

Answers (1)

Oliver Cooke
Oliver Cooke

Reputation: 1059

Just define 2 interfaces with your required values.

export interface ParentModel {
    Name: string;
    Id: number;
    Store: ChildModel
}

export interface ChildModel {
    Name: string;
    City: string;
    State: string;
}

Depending on how you want to set it up these can be in the same file or two separate files, if you are putting them in separate files just remember to import the child into the parent.

Hope that helps

Upvotes: 3

Related Questions