I want to use (click)
function only when ngIF
have value True
.
<tbody class="table-hover domains">
<tr *ngFor="let domain of domains" (click)="gotoDetail(domain.id)">
<td class="col-md-3">{{ domain.name }}</td>
<td>{{ domain.validated }}</td>
</tr>
</tbody>
So I need to add ngIF
in <tr>
tag as if {{ domain.validated }}
value is True
, then (click)
function works, else it don't work or show message that variable have value False
. How to do that?
The *ngIf directive is most commonly used to conditionally show an inline template, as seen in the following example. The default else template is blank.
We can use multiple conditions in *ngIf with logical operator AND (&&) to decide the trustworthy of *ngIf expression. If all conditions are true, then element will be added to the DOM.
The ngIf directive removes or recreates a portion of the DOM tree based on an {expression}. If the expression assigned to ngIf evaluates to a false value then the element is removed from the DOM, otherwise a clone of the element is reinserted into the DOM.
Try *ngIf="condition && yourfunction()" . Your function must return true to the if evaluate to true, but it will only be executed if your condition is true, since an and operator will stop on first false.
Try using this:
<tbody class="table-hover domains">
<tr *ngFor="let domain of domains" (click)="!domain.validated || gotoDetail(domain.id)">
<td class="col-md-3">{{ domain.name }}</td>
<td>{{ domain.validated }}</td>
</tr>
</tbody>
Hope it will work for you .
The function will only be called if first part(!domain.validated) will return false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With