Learn how to declare if statements within a template, as well as else and then.
- [Instructor] One of the most basic elements…of programming is the if else statement and, surprisingly,…up until version four Angular did not support else.…Fortunately, now it does.…If, else, and then are all defined…within the ngIf directive.…We define ngIf inside of an HTML element…and inside of the quotes we bind it…to a template expression.…When we add else, we're able…to define a local template variable and, when we add them,…we can define a local template variable…based on the template expression resulting in true or false.…
So let's give it a try in our own project.…We currently have a title property on line 16.…Let's add an if statement and an h1 tag.…So let's go ahead and remove all of our HTML to this point.…And let's add an h1 tag…and this is where we add the ngIf directive…so *ngIf="title"…and we'll simply add...…
"I'm here" and we'll save it, go back to our browser,…and, as you can see, the h1 element remains…because the title property is present…in our component class.…Now if we add a not operator on title,…
Author
Released
6/2/2017- How components work
- Defining HTML templates
- Defining CSS
- Interpolation
- NgFor
- NgSwitch
- Class binding and style binding
- Property binding and event binding
- Animation
- Creating routes for navigation
Skill Level Intermediate
Duration
Views
Related Courses
-
Angular Testing and Debugging
with Derek Peruo1h 16m Intermediate
-
Introduction
-
Welcome45s
-
-
1. Getting Up and Running with Angular
-
How components work2m 27s
-
Defining HTML templates2m 49s
-
Defining CSS3m 1s
-
2. Templating Basics
-
Interpolation2m 8s
-
NgFor3m 47s
-
NgIf, Else, and Then4m 12s
-
NgSwitch2m 59s
-
-
3. Data Binding
-
Local variables3m 32s
-
Class binding3m 56s
-
Style binding2m 41s
-
Property binding2m 12s
-
Event binding5m 25s
-
-
4. Animation
-
Transitions3m 43s
-
Multi-step animations3m 39s
-
5. Tying It All Together
-
Project preview53s
-
Starting the project2m 53s
-
Header template7m 40s
-
Products template10m 1s
-
Products component7m 17s
-
-
Conclusion
-
Next steps51s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: NgIf, Else, and Then