Quick Notes: Use enums instead of string comparisons for *ngIf
Make reading code easy on the eyes

I am a developer from Toronto, Canada and I enjoy writing about JavaScript, Angular and the .NET framework.
Search for a command to run...
Make reading code easy on the eyes

I am a developer from Toronto, Canada and I enjoy writing about JavaScript, Angular and the .NET framework.
No comments yet. Be the first to comment.
What does 99.99% mean?

Using Projections - getting related data

Expose an entity using HotChocolate

Reactive programming is somewhat of a shift in thinking on how you get values from a source of data. Instead of you asking the source every few seconds for an update, the source sends you data you are interested in over time. In other words, we are t...

Learn to create your own tags like control

As I spend time reviewing code, I have come to realize how important it is to write code that makes it easy for someone else to read. This is especially important when working with HTML templates because it can end up being a lot of lines.
Take a look at the following code:
<div *ngIf="user=='A'">User is Admin</div>
<div *ngIf="user=='O'">User is Owner</div>
This code looks straight forward and innocent enough. However, the developer has to spend time to recall what the values 'O' and 'A' stand for. Furthermore, what if these values were to change in the future? Or, worse, imagine we used these if statements in multiple places within our html template!
Instead, we could do this:
<div *ngIf="user === User.ADMIN">User is Admin</div>
<div *ngIf="user === Users.OWNER">User is Owner</div>
This syntax stands out, and more importantly, we are able to use labels that actually make it easier to read the html template code.
At the end of the day, whenever you find yourself using string within the {{ and }} brackets - think if there is a better way to do that work (maybe using a variable, getter or pipe), or, by using enums.