I am creating small application to get html content from website url using angular cli. i have added imported all required file but i am getting this error:
XMLHttpRequest cannot load https://www.test.org/publicclass/index.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
how we can solve this issue.
script:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as jQuery from 'jquery';
import { Http, Headers, RequestOptions } from '@angular/http';
@Component({
selector: 'app-bodycontent',
templateUrl: './bodycontent.component.html',
styleUrls: ['./bodycontent.component.css']
})
export class BodycontentComponent implements OnInit {
title = 'app';
results = '';
constructor(private http: HttpClient){
}
ngOnInit(): void {
let headers = new Headers({ 'Content-Type': 'text/html' });
let options = new RequestOptions({ headers: headers });
this.http.get('https://www.test.org/publictest/index.html').subscribe(html => {
alert(html);
});
}
}