How to check empty object in angular template using ngIf

0 votes

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?

Sep 8, 2020 in Angular by kartik
• 37,520 points
18,558 views

1 answer to this question.

0 votes

Hello @kartik,

Use this:

<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

Hope it helps!!

To know more about Angular, Join Angular Training Course today.

Thank you!!

answered Sep 8, 2020 by Niroj
• 82,840 points

Related Questions In Angular

0 votes
1 answer

How to know tools and bundlers after create a new workspace or a project in angular?

Hello @sajal, When you create projects and workspaces ...READ MORE

answered Aug 6, 2020 in Angular by Niroj
• 82,840 points
928 views
0 votes
1 answer

How to Stop observable.timer in Angular?

Hello @kartik, There're are basically two ways: call unsubscribe() on the ...READ MORE

answered Sep 8, 2020 in Angular by Niroj
• 82,840 points
14,533 views
0 votes
0 answers

How to change the value of an Observable in TypeScript Angular?

How to change the value of an ...READ MORE

Nov 26 in Angular by Nidhi
• 3,920 points
38 views
0 votes
0 answers

How to transfer data between two unrelated components in Angular?

How to transfer data between two unrelated ...READ MORE

Nov 26 in Angular by Nidhi
• 3,920 points
33 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,216 views
+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28, 2020 in Java-Script by Niroj
• 82,840 points
18,741 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
3,284 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
1,323 views
0 votes
2 answers

How to detect a route change in Angular?

Hii Kartik For Angular 7 someone should write like: this.router.events.subscribe((event: Event) ...READ MORE

answered Apr 22, 2020 in Angular by Niroj
• 82,840 points
29,246 views
0 votes
3 answers

How to load external scripts dynamically in Angular?

Hello kartik, You can use following technique to ...READ MORE

answered Apr 22, 2020 in Angular by Niroj
• 82,840 points
71,828 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP