繁体   English   中英

ngIf在角度2中

[英]ngIf In angular 2

如果paymentdone我想显示一个按钮。 下面是我使用ngIf的Angular HTML代码:

<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>

但似乎ngIf无法正常工作。

我该怎么做? 有人可以帮我吗?

您不需要在*ngIf中使用*ngIf

您只需要=>

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

无需使用插值。

尝试以下

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

工作示例 https://stackblitz.com/edit/angular-8anxaf

ngIf语法看起来像这样* ngIf =“ exprestion”,如果exprestion的值为true或比较表达式(如property === value ,则其可以是检查组件的属性

在您的情况下,只需将支出更新为

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

如果app_list未初始化,或者该值是异步操作的结果,则不需要,您需要使用“?”。 (安全导航运算符)运算符,这样您就不会出现错误,无法读取未定义的paymentdone

最终解决方案如下所示

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

您只需要删除* ngIf中的bracet并使其简单即可

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM