I will like to read an XML file from found in src/assets/test.xml
. I have a component found in src/app/app.component.ts
as so:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {
constructor(private router: Router, private httpClient: HttpClient) {
this.getProducts();
}
getProducts() {
const headers = new HttpHeaders();
headers.set('Content-Type', 'text/xml');
this.httpClient
.get('assets/test.xml', { headers, responseType: 'text' })
.subscribe(output => console.log(output));
}
}
Inside the app.module.ts
I have imported the HttpClientModule
as required and the only error message I receive is:
{
body: {error: "Collection 'test' not found"},
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ},
status: 404,
statusText: "Not Found",
url: "assets/test.xml"
}
I tried with other assets in the assets
folder but still without any success. Can anyone help me out please?