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

前端 未结 7 1235
逝去的感伤
逝去的感伤 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 16:53

    A bit of a lengthier way (if interested in it):

    In your typescript code do this:

    this.objectLength = Object.keys(this.previous_info).length != 0;
    

    And in the template:

    ngIf="objectLength != 0"
    

提交回复
热议问题