Learn about ngSwitch and ngSwitchCase to display one element based on a condition.
- [Instructor] NgSwitchCase is a directive…that allows you to specify a property…and based on the value, show one…of multiple template elements.…This is useful when a given property…can equal multiple values.…The syntax for NgSwitchCase is to wrap…ngSwitch in brackets and then binding it to a property.…Then nest it inside of the element…that contains the ngSwitch directive…you add ngSwitchCase and bind it to…any of the possible values that the property could match.…If the given SwitchCase is true,…it will show the element in the DOM.…
Let's go back to our project.…Here on line 17 we have our default title property.…Let's change it,…likes = 'baseball';…and in our template,…let's get rid of this div…and let's add a new div…and we wrap ngSwitch in brackets…and we bind it to our property "likes."…Inside is where we specify each ngSwitchCase,…*ngSwitchCase, then single quote, baseball,…Display baseball content,…we'll copy and paste this twice…and we'll change this here to football,…and this one basketball.…
All right, we'll save this…
- 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 48m 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.