0

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 ?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.