Services in Angular2

Create a Employee service

import { Injectable,Inject } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
export class ServicesComponent {
  private _dataURL:string = "../../assets/data/output.json"; 
  constructor(@Inject(Http) private _http: Http) { }
      return this._http.get(this._dataURL)
    .map((res:Response) =>  res.json());


Working demo of Angular 4 service Demo Link Angular 4 service files

43 thoughts on “Services in Angular2

Leave a Reply

Your email address will not be published. Required fields are marked *