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';
@Injectable()
export class ServicesComponent {
  
  private _dataURL:string = "../../assets/data/output.json"; 
  constructor(@Inject(Http) private _http: Http) { }
  getDetails(){
      return this._http.get(this._dataURL)
    .map((res:Response) =>  res.json());
    
  }
 

}

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

Leave a Reply

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