Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular – How to display detail based on condition

I want to display the detail of employee from ASP.NET Core Web API using Angular-13.

I have these end_points:

{
    "id": 1,
    "employee_name": "Frank Lammmy",
    "charge_mode": 1,
    "charge_value": 12344.55,
    "charge_percent": 
}

What want to achieve on the employee detail is this: if charge_mode = 1, it should display charge_value, but if charge_mode = 2 it should display charge_percent.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried this:

  <div class="col-md-6">
    Employee Name: <strong>{{ employeeList.employee_name || 'N/A' }}</strong>
  </div>
  <div class="col-md-6">
    *ngIf="employeeList.charge_mode === 1" Amount: <strong>{{ employeeList?.charge_value || 'N/A' }}</strong>
    *ngIf="employeList.charge_mode === 2" Percentage (%): <strong>{{ employeeList?.charge_percent || 'N/A' }}</strong>
  </div>

but it’s not working, it just display the raw data.

How do I achieve this?

>Solution :

Your provided code is close, but you’ll want to apply the *ngIf directives to some HTML elements.

  <div class="col-md-6">
    Employee Name: <strong>{{ employeeList.employee_name || 'N/A' }}</strong>
  </div>
  <div class="col-md-6">
    <span *ngIf="employeeList.charge_mode === 1">Amount: <strong>{{ employeeList?.charge_value || 'N/A' }}</strong></span>
    <span *ngIf="employeeList.charge_mode === 2">Percentage (%): <strong>{{ employeeList?.charge_percent || 'N/A' }}</strong></span>
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading