Condition based click event in Angular 2

前端 未结 2 1260
轮回少年
轮回少年 2020-12-08 04:07

In my application I would like to have conditional based click event ,

0) {removeSelected(item.spId)}\"
相关标签:
2条回答
  • 2020-12-08 04:38
    (click)="idx > 0 && removeSelected(item.spId)"
    
    0 讨论(0)
  • 2020-12-08 04:39

    Simply use a ternary:

    <div class="trashIconDiv" (click)="idx > 0 ? removeSelected(item.spId) : false">
    

    This will only call removeSelected function when the condition is true, if it's false then it won't do anything.

    0 讨论(0)
提交回复
热议问题