Angular2 *ngIf check object array length in template

后端 未结 5 641
北恋
北恋 2020-12-12 23:43

Refered to https://angular.io/docs/ts/latest/guide/displaying-data.html and stack How to check empty object in angular 2 template using *ngIf still getting syntax error self

5条回答
  •  -上瘾入骨i
    2020-12-12 23:45

    Maybe slight overkill but created library ngx-if-empty-or-has-items it checks 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

提交回复
热议问题