Sometimes we need to direct the data flow from the template to the component. In other words, we need to listen for an event in a DOM element and act upon it inside the Component class. That means we need to bind a method to an event--that is why it is called event binding.
The event binding syntax is very easy. On the left side, we mention the name of the event we are interested in, and on the right side we write the method name--in the component class--which this event will be bound to:
(event) = "onEvent(parameters)"
To see how it works, let's listen for checked headlines and show them in the console. Later in this chapter, we will see how to persist the selected headlines in a database for future reference. But for now logging them in the browser's console will be enough.
First we need to listen for change events on the checkbox elements, so modify the
<input>
tag as follows:# app/collector/collector.html # ... <li *ngFor="let headline...