user10483925
user10483925

Reputation: 1

ngIf In angular 2

I want to display a button if paymentdone is due. Below is my HTML code for Angular using ngIf:

<tr>
           <td class="table-id">{{app_list.testbookingmasterid}}</td>
      <td>{{app_list.userid}}</td>
      <td>{{app_list.patientname}}</td>
      <td>{{app_list.paymentdone}} 
        <ng-container *ngIf="{{app_list.paymentdone}}==='due'">
          <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" (click)="demo(app_list.testbookingmasterid,app_list.userid)" ><i class="fa fa-edit"></i>&nbsp;Process</button>
   </ng-container> </td>
      <td>{{app_list.comments}}</td>  
      </tr>

But it seems ngIf is not working.

How can I do it? Can anyone help me in this?

Upvotes: 0

Views: 88

Answers (4)

Abdullah Khan
Abdullah Khan

Reputation: 645

you just have to remove bracet in *ngIf and make it simple

*ngIf="app_list.paymentdone==='due'"

Upvotes: 0

Muhammed Albarmavi
Muhammed Albarmavi

Reputation: 24464

ngIf syntax look like this *ngIf="exprestion" , the exprestion can be a check component property if it value truthy or comparison expression like property === value

in your case just update the exprestion to this

  *ngIf="app_list.paymentdone === 'due'"

not if app_list is hasn't initialize or the value will be a result of async operation you need to use '?.' (safe navigation operator) operator so you dont got an error can't read paymentdone of undefined

final solution look like this

<ng-container *ngIf="app_list?.paymentdone === 'due' ">
  ...
</ng-container>

Upvotes: 0

Prakash Chidambaram
Prakash Chidambaram

Reputation: 1

There is no need to use interpolation.

Try the following

<ng-container *ngIf="(payment==='due')">
          hello payment mode due
</ng-container> 

Working Example https://stackblitz.com/edit/angular-8anxaf

Upvotes: 0

Micka&#235;l Depardon
Micka&#235;l Depardon

Reputation: 21

You don't need bracet in an *ngIf.

You only have to do =>

*ngIf="app_list.paymentdone==='due'"

Upvotes: 2

Related Questions