Condition based click event in Angular 2

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

<div class="trashIconDiv" (click)="if(idx > 0) {removeSelected(item.spId)}">

In the above code removeSelected function should be executed only when idx >0 , any idea how to implement


(click)="idx > 0 && removeSelected(item.spId)"

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.