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,…
- How components work
- Defining HTML templates
- Defining CSS
- Class binding and style binding
- Property binding and event binding
- Creating routes for navigation
Skill Level Intermediate
Angular 2 Essential Trainingwith Justin Schwartzenberger2h 45m Intermediate
Angular 2: Widget-Based Architectureswith Derek Peruo52m 18s Intermediate
1. Getting Up and Running with Angular
2. Templating Basics
3. Data Binding
5. Tying It All Together
- 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.Cancel
Take 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.