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.
ngIf is the directive. Because it's a structural directive (template-based), you need to use the * prefix to use it into templates. *ngIf corresponds to the shortcut for the following syntax (“syntactic sugar”): <template [ngIf]="condition">
Consider the following code sample:
<div *ngIf="condition; else elseBlock">
<!-- markup here -->
</div>
<ng-template #elseBlock>
<div>
<!-- additional markup here -->
</div>
</ng-template>
Another way I can achieve the same functionality is:
<div *ngIf="condition">
<!-- markup here -->
</div>
<div *ngIf="!condition">
<!-- additional markup here -->
</div>
I want to know specific reasons for which of these two ways should be used and why?
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