How to check empty object in angular 2 template using *ngIf

前端 未结 7 1218
逝去的感伤
逝去的感伤 2020-12-04 16:26

I want to check if my object is empty dont render my element, and this is my code:


      
7条回答
  •  借酒劲吻你
    2020-12-04 17:10

    Just for readability created library ngx-if-empty-or-has-items it will check if an object, set, map or array is not empty. Maybe it will help somebody. It has the same functionality as ngIf (then, else and 'as' syntax is supported).

    arrayOrObjWithData = ['1'] || {id: 1}
    
    

    You will see it

    or // store the result of async pipe in variable

    {{obj.id}}

    or noData = [] || {}

    You will NOT see it

提交回复
热议问题