Outline

Exercise Goal

Use the HostListener() decorator to listen for events.

Tasks

  1. Define a new onClick() method in the AppComponent class. When the method is invoked simply alert the user using the window.alert() method. You can have it say whatever you prefer.
  2. Decorate the onClick() method using the @HostListener() decorator, specifying the click event.

Exercise

Exercise Problem

Notes

  • The @HostListener() function accepts a single argument: the name of the event on which to listen.
  • Don't use the "onClick" or "onMouseover" syntax that is used in HTML for attaching an event listener to an element, rather, just specify the event, such as: "click" or "mouseover".
 

I finished! On to the next chapter