⚠️ This lesson is retired and might contain outdated information.

Control Angular 2 Events with $event and Event Handlers

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 2 years ago

This lesson talks about the benefits of using the parens-based (click) syntax so that Angular 2 can handle any custom event. Then the video explains how to pass in the actually event object using the familiar $event syntax.

[00:00] If you need to get the actual MouseEvent, you can use the "$Event" syntax, which is just the same way we did it in Angular 1, so that the Event will be passed along. Now this value is the actual MouseEvent, so now when I click on this button, you'll see MouseEvent with all the properties you would expect from the MouseEvent.

[00:19] After that Event, you can go ahead and type ", myInput.value" and as well say that this is the Event, and we want to log out the Event, and then the value, so the "$Event" is here, the input value is here, and we're logging out the Event and the value. Now when we click and I type something, "Hello," and click, you'll see the MouseEvent and the value of "Hello."

[00:45] This will work on any DOM Event. If you were to say "mouseover" and hit save, now instead of onclick, every time I mouse over this button, you'll see those MouseEvents firing, and the value "Hello" of the form logging out as well.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today