Home > OS >  NgIf and NgElse in Angular/HTML
NgIf and NgElse in Angular/HTML

Time:09-23

In my fields Buy/Sell and Quantity I enter a value for each field. I confirm via a button.

enter image description here

And I get my values...

enter image description here

<div class="card mb-4" *ngIf='currentView == 1 && order.quantity > 0 && order.sense !=  "" '>
<div class="card-body">
<div class="row ml-0 mb-4" >
   <ng-container *ngIf="order.sense === 'A'">Buy {{ order.quantity }}  </ng-container>
   <ng-container *ngIf="order.sense === 'V'">Sell {{ order.quantity }}  </ng-container>
</div>

My problem is that if I have 3 fields to complete, I have to retrieve another message:

enter image description here

enter image description here

How to I can adapt this line in in my code above

<ng-container *ngIf="order.sense === 'A'">Buy {{ order.quantity }} - Limite {{ order.limit }} </ng-container>

CodePudding user response:

You could do something like this assuming thatyou want to conditionally render order.limit:

          <ng-container *ngIf="order.sense === 'A'">
            Buy {{ order.quantity }}
            <span *ngIf="order.limit > 0">
               - Limite {{ order.limit }}
            </span>
          </ng-container>
  • Related