Display empty list message
- βοΈDisplay HTML content conditionallyLearn how to use the *ngIf directive to display HTML content conditionally.
You just learned how to delete a task from the list, and you want to display a message when the list is empty.
The *ngIf directive
To iterate over the tasks list, you used the *ngFor directive. Known as a structural directive, it affects the layout by adding, removing, or manipulating elements in the DOM.
Another common structural directive is the *ngIf directive. It allows you to conditionally display an element in the view.
By passing it a condition, the element its used one is displayed only when the condition is true.
π Instructions
-
Update the
src/app/task-list.component.html
file.
Letβs test it out
- Remove all the tasks from the list.
- The message βNo tasks to displayβ should be displayed in the view.
βοΈ What you learned
In this chapter, you learned how to use the *ngIf directive.