Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Angular Services

You're reading from   Angular Services -

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781785882616
Length 294 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sohail Salehi Sohail Salehi
Author Profile Icon Sohail Salehi
Sohail Salehi
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Angular Services
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Setting Up the Environment FREE CHAPTER 2. Introducing Wire-Frames 3. The Collector Service - Using Controllers to Collect Data 4. The Rating Service - Data Management 5. The Notifier Service - Creating Cron Jobs in Angular 6. The Evidence Tree Builder Service - Implementing the Business Logic 7. The Report Generator Service - Creating Controllers to Set Report Template 8. The Accuracy Manager Service - Putting It All Together

Event binding


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.

  1. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images