get the type of input and cast it in Angular

Discussão em 'Angular' iniciado por sanjihan, Outubro 30, 2024.

  1. sanjihan

    sanjihan Guest

    I am passing @Input() element variable to the app-child component

    <app-child [element]="element"></app-child>


    element is an object. It can be of many types, lets say Blue, Red or Green

    Inside ChildComponent.ts, how can I determine the type of element and cast it to the correct type? instanceof cannot be used with variables of type any.

    `ChildComponent.ts`

    @Input() element: any; // is it of type Blue, Red or Green?

    Continue reading...

Compartilhe esta Página