Consuming Angular Services
In my previous post, i talked about simple Angular Services. Now we’ll provide these services throughout our app and we’ll use their functions in a component. Let’s say we have this service named as sample.service.ts: import { Injectable } from '@angular/core'; @Injectable() export class SampleService{ private data : Array<any>; getUsers(){ if(this.data === null || this.data.length === 0) this.seed(); return this.data; } private seed(){ this.data = [ "Ahmet", "Murat", "John", "Jeffrey", "Benjamin" ]; } } And we want to consume this service, by invoking it from our component....