Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Control Angular 2 Events with $event and Event Handlers

    5 - 6

    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    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.

    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."

    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.