How to check type of variable in ngIf in Angular2

后端 未结 5 2073
鱼传尺愫
鱼传尺愫 2020-12-14 05:23

I\'m learning Angular2. I have a component with a variable which is an object. I\'m iterating over the fields of the object, and acording to the type of data of that positio

5条回答
  •  情书的邮戳
    2020-12-14 06:00

    Globals like window, typeof, enums, or static methods are not available within a template. Only members of the component class and typescript language constructs are available.

    You can add a helper method to your component like

    isNumber(val): boolean { return typeof val === 'number'; }
    

    and use it like

提交回复
热议问题