In this video, learn how to use the Angular template syntax to bind logic to a DOM element event.
- [Instructor] The EventBinding template syntax in Angular allows you to wire up event handlers from within your component templates. You can wire up native dom element events, as well as custom events you create for your components to emit. Let's take a look at how you wire up to native events. Our media-item.component.html file has a delete link. Let's add some quick functionality to that. Where property binding makes use of the square brackets, event binding makes use of parentheses, so on the a tag element for the delete, we can add the event named click, wrapped with parentheses, and set it equal to a statement in quotes that will be evaluated. Let's bind this to a function call of a function named onDelete. Notice that we use the term click here, and not onClick. Angular has a pattern for native dom events where it is looking for the event name without the on, so any native dom event that is named on x, you would bind it by leaving off the on prefix. Angular is expecting the onDelete method to be available in the execution context. Remember that we can make a method available by putting it on the component class. So let's switch to the media-item.component.ts file, and add an onDelete method. In here we would run our delete logic, which we will implement later. For now, let's console log a message and see it in action. So if we switch over to the browser, and with the console and the dev tools open, click on the remove link, and see our console log output from our event binding.
- What is Angular?
- Working with components
- Binding events and properties
- Getting data to components
- Using directives and pipes
- Creating Angular forms
- Validating form data
- How Angular does dependency injection
- Making HTTP calls
- Styling components
Skill Level Intermediate
Angular: Building an Interfacewith Ray Villalobos2h 20m Intermediate
1. Architecture Overview
3. Directives and Pipes
5. Dependency Injection and Services
8. Styling Components
Next steps1m 20s
- 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.