Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
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
Toc

Table of Contents (9) Chapters Close

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

The evidence service


Let's start by creating an empty service and creating a very basic structure for its functions. Create a new TypeScript file inside the evidence/ folder and add the following contents to it:

// src/app/evidence/evidenc.service.ts 
import {Injectable} from "@angular/core"; 
 
@Injectable() 
export class EvidenceService { 
  private words = [ {key:"w1",value:1}, {key:"w2",value:2} ]; 
  wordCounts(url) { 
    // ToDo: get a url subscribe to its response and call other 
    // functions to count the words and their occurrence in it. 
    // Ideally it will return an array of objects. 
    return words; 
  } 
} 

So the draft version of our service is very simple. It gets a URL which contains the article of our interest and then finds and returns all unique words and number of their instances.

Before implementing these functions, we need to get the URL and find a way to extract useful content out of it. The important question here is how we distinguish between HTML tags and...

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 $19.99/month. Cancel anytime
Banner background image