Learn how to define and access local variables in a template.
- [Instructor] Local template variables…allow you to reference and access HTML elements…and their associated properties…within other HTML elements in the view.…Now, defining a local variable is simple.…You use the hash sign and the name of the variable.…Then, depending on where you want to use that variable,…you use interpolation with the local variable name inside.…So, let's give it a try.…We can attach a local variable to any HTML element.…So, let's go ahead and get rid of…all of our current template.…
Here, we'll do an h1 and we'll define a local variable…with the hash sign myH1 inside,…my title and then we can also reference it…with a <p> tag here through interpolation, my H1.…So, let's save and go to our browser.…Now, we can see this local variable is an object.…
So, in order to use it,…we have to specify one of its properties.…So, myH1, we can use inner text, for instance,…to get it's text.…Alright, now, a more common example…is to attach a local variable to an input element.…So, let's say we wanted to get a word count on a text field.…
- 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
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.