Угловая защита Блокирует динамический рендеринг HTML и других скриптов. Вам нужно обойти их, используя DOM Sanitizer.
Подробнее здесь: Угловая защита
НЕ СЛЕДУЕТ вносить изменения в ваш код:
// in your component.ts file
//import this
import { DomSanitizer } from '@angular/platform-browser';
// in constructor create object
constructor(
...
private sanitizer: DomSanitizer
...
){
}
someMethod(){
const headers = new HttpHeaders({
'Content-Type': 'text/plain',
});
const request = this.http.get<string>('https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Your_first_HTML_form', {
headers: headers,
responseType: 'text'
}).subscribe(res => this.htmlString = res);
this.htmlData = this.sanitizer.bypassSecurityTrustHtml(this.htmlString); // this line bypasses angular security
}
и в HTML-файле;
<!-- In Your html file-->
<div [innerHtml]="htmlData">
</div>
Вот рабочий пример вашего требования:
Рабочая демонстрация Stackblitz