Search code examples
angularangular12

Angular interface adding subitems how to


I want to categorise the interface items in my dashboard so I’m trying something like this:

export interface MyInterface {
    title?: string;
    dashboard: any[
        { 
        id: number; 
        label: string; 
        key: any
        // etc…
    };
    ] 
}

How can I do this?


Solution

  • This is what I would suggest. Its more redable in the sense that it specifies "an array of type"

    export interface Dashboard{
      id: number;
      label: string;  
      key: any;
    }
    export interface MyInterface {
      title?: string;
      dashboard: Dashboard[];
    }