Sandip Nag
Sandip Nag

Reputation: 998

Creating an Interface of a data consist of object and array of objects

I have a data set like this:-

data = {
   restDetails":{
           id:1
           name:"Rest1"
     },
    menus:[{
           id:1,
           name:"Dish1"
      },
      {
           id:1,
           name:"Dish2"
      }]
}

I am new to Angular 5. I want to create an interface for this data set in Angular 5 project. How can I achieve this? Thanks

Upvotes: 1

Views: 40

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222720

You can use JSON2TS to create an interface based on your JSON data,

interface RootObject {
  restDetails: RestDetails;
  menus: RestDetails[];
}

interface RestDetails {
  id: number;
  name: string;
}

Upvotes: 3

Related Questions