import { Component , OnInit } from "@angular/core" ; import { MyHttpGetService } from "./http-get.services" ; @ Component ( { moduleId : module . id , templateUrl : "./http-get.component.html" , providers : [ MyHttpGetService ] } ) export class HttpGetComponent implements OnInit { host : string ; userAgent : string ; origin : string ; url : string ; constructor ( private myService ) { } ngOnInit ( ) { this . extractData ( ) ; } extractData ( ) { this . myService . getData ( ) . subscribe ( ( result ) => { this . onGetDataSuccess ( result ) ; } , ( error ) => { console . log ( error ) ; } ) ; } private onGetDataSuccess ( res ) { this . host = res . headers . Host ; this . userAgent = res . headers [ "User-Agent" ] ; this . origin = res . origin ; this . url = res . url ; } }