Book Image

Angular Services

Book Image

Angular Services

Overview of this book

A primary concern with modern day applications is that they need to be dynamic, and for that, data access from the server side, data authentication, and security are very important. Angular leverages its services to create such state-of-the-art dynamic applications. This book will help you create and design customized services, integrate them into your applications, import third-party plugins, and make your apps perform better and faster. This book starts with a basic rundown on how you can create your own Angular development environment compatible with v2 and v4. You will then use Bootstrap and Angular UI components to create pages. You will also understand how to use controllers to collect data and populate them into NG UIs. Later, you will then create a rating service to evaluate entries and assign a score to them. Next, you will create "cron jobs" in NG. We will then create a crawler service to find all relevant resources regarding a selected headline and generate reports on it. Finally, you will create a service to manage accuracy and provide feedback about troubled areas in the app created. This book is up to date for the 2.4 release and is compatible with the 4.0 release as well, and it does not have any code based on the beta or release candidates.
Table of Contents (15 chapters)
Angular Services
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Updating the component and the service


In order to respond to the Calculate IDF button inside the template, all we need to do in the component is catch the click event and call the related function from the service. So just add the onIDFs() function as follow:

// src/app/evidence/evidence.component.ts 
// ... 
export class EvidenceComponent implements OnInit{ 
  // ... 
  onIDFs() { 
    this.evidenceService.saveIDFs(); 
  } 
} 

However, on the service side, we have a lot of work to do. We can summarize the required steps for IDF calculations as follow:

  1. Remove previous IDF calculations: every time a new article is added to the corpus, it makes all previous IDF calculations invalid, so we need to erase them before starting the new calculations.

  2. Loop through articles and gather all unique words by looking into bag of words for each article. This will be a corpus-level bag of words or a bag of words made out of all available bags of words if you like.

  3. Loop through unique words and find the number...