Member-only story
Until a while ago, I still couldn’t convince myself when I should use Angular If Else Directives.
This is due to most of the time, writing 2 *ngIf
(refer the below code) was enough to support my use case.
My 2 *ngIf validation
The ngIf else way
Why ngIf else?
After several rounds of thinking, I finally able to discover the reasons that are enough to persuade myself to use ngIf else
.
- Firstly, using
ngIf else
allows you to reduce one if validation. You don't have to write two*ngIf
validation. - Secondly, you can reuse the
loadingView
declared above code. For e.g, you can reuse theloadingView
when you're retrieving data from server or submitting data to server.
Originally published at https://tekloon.dev.