I've followed the tutorial on the angular site (https://angular.io/guide/http) but I can't achieve what I want since I have an error that I don't understand. I've put my text file in the assets doc and created a config.json file where I entered the code from the tutorial. I get errors in my service.ts file and component.ts file aswell. Please help me understand my errors and the tutorial.
Component.ts
import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {HttpClient, HttpErrorResponse, HttpResponse} from '@angular/common/http';
import {GeneralService} from '../general.service';
@Component({
selector: 'app-general',
templateUrl: './general.component.html',
styleUrls: ['./general.component.css']
})
export interface General {
generalUrl: string;
textfile: string;
}
export class GeneralComponent implements OnInit {
title = 'Introduction';
generalUrl = 'assets/project_description.txt';
general: General;
generalService: GeneralService;
constructor(private http: HttpClient) { }
ngOnInit() {
}
getGeneral() {
return this.http.get(this.generalUrl);
}
showGeneral() {
this.generalService.getGeneral()
.subscribe(data => this.general = {
generalUrl: data['generalUrl'],
textfile: data['textfile']
});
}
showGeneralResponse() {
this.generalService.getGeneralResponse()
.subscribe(resp => {
const keys = resp.headers.keys();
this.headers = keys.map(key =>
`${key}: ${resp.headers.get(key)}`);
this.config = {
});
}
}
On my showGeneralResponse() function headers and config are unresolved variables
Service.ts
import { Injectable } from '@angular/core';
import {General} from './general/general.component';
import {HttpResponse} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class GeneralService {
constructor() { }
getGeneral() {
return this.http.get<General>(this.generalUrl);
}
getGeneralResponse(): Observable<HttpResponse<General>> {
return this.http.get<General>(
this.generalUrl, { observe: 'response'}
);
}
}
In getGeneral() and getGeneralresponse() functions I have http and generalUrl who are unresolved variables
But in my config.json file I have no error
config.json
"generalUrl": "api/general",
"textfile": "assets/project_description.txt"
I also would like to know which function to put in my html file so my application would display me my file text

showGeneralResponse() { this.generalService.getGeneralResponse() .subscribe(resp => { const keys = resp.headers.keys(); this.**headers** = keys.map(key => ${key}: ${resp.headers.get(key)}); **this.general** = { }); }the error is in headers and it says that it's an unresolved variable And I don't know what to put in the brackets of this.generalgetGeneral() { return this.http.get(this.generalUrl).map((res: Response) => res.json()); }