Home > database >  Angular interface adding subitems how to
Angular interface adding subitems how to

Time:10-07

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?

CodePudding user response:

dashboard: { 
    id: number; 
    label: string; 
    key: any
    // etc…
}[];

you put the type of what's in the array before the array notation, denoting that it is an array of this type, rather an array of any which is what any[] means.

CodePudding user response:

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[];
}
  • Related