在Angular 2中有条件地触发单击事件功能

问题描述 投票:0回答:1

我有一个Angular 2应用程序,其中有一个表格,列中有复选框。当用户单击复选框时,将显示一个模式,其中包含有关该行的更多详细信息。但是,如果选中复选框,我只想显示模态。这就是我现在拥有的:

<tr *ngFor="let item of searchItems">
  <td><input type="checkbox" name="rowCheckbox" (click)="setSelectedRow(item);modal.show();" /></td>
 ...

</tr>

我可以向modal.show()申请条件吗?像if(this['checked']){modal.show();};这样的东西?

angular angular2-template
1个回答
0
投票

将FormsModule导入到组件的模块中,将checked:boolean变量添加到组件类中,然后像下面这样更改输入:

<input type="checkbox" [(ngModel)]="checked" name="rowCheckbox" (click)="setSelectedRow(item); checked ? modal.show() : '';" /></td>

您不能在Angular的表达式中使用if语句,但可以使用三元运算。

© www.soinside.com 2019 - 2024. All rights reserved.