import { Component , OnInit } from '@angular/core' ; import { AppService } from './app.service' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; @ Component ( { templateUrl : './home.component.html' } ) export class HomeComponent { title = 'Demo' ; greeting = { } ; constructor ( private app , private http ) { http . get ( 'token' ) . subscribe ( data => { const token = data [ 'token' ] ; http . get ( 'http://localhost:9000' , { headers : new HttpHeaders ( ) . set ( 'X-Auth-Token' , token ) } ) . subscribe ( response => this . greeting = response ) ; } , ( ) => { } ) ; } authenticated ( ) { return this . app . authenticated ; } }