Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  193] [ 6]  / answers: 1 / hits: 197163  / 8 Years ago, mon, may 9, 2016, 12:00:00

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


<div class="comeBack_up" *ngIf="previous_info != {}">
<a [routerLink]="['Inside_group_page',{'name':previous_info.path | dotTodash }]">
{{ previous_info.title }}
</a>
</div>

but my code is wrong, what is the best way to do this?


More From » typescript

 Answers
20

This should do what you want:



<div class=comeBack_up *ngIf=(previous_info | json) != ({} | json)>


or shorter



<div class=comeBack_up *ngIf=(previous_info | json) != '{}'>


Each {} creates a new instance and ==== comparison of different objects instances always results in false. When they are convert to strings === results to true



Plunker example


[#62256] Friday, May 6, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oswaldoh

Total Points: 109
Total Questions: 93
Total Answers: 113

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;