NG7 - Sanitize HTML in Angular Template
================================
import {Component, Input, OnInit} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser'
@Component({
selector: 'iframebasedHTML',
template: `
<main>
<div>
<iframe class="embed-responsive-item" [srcdoc]="externFullHtml" allowfullscreen></iframe>
</div>
</main>
`
})
export class ExternHTMLComponent implements OnInit{
extHtml: SafeHtml;
externFullHtml = `
<html>
<meta charset="utf-8">
<head>
</head>
<body>
<div id="fixedContent">
<span> left content </span>
<span> right content </span>
</div>
</body>
</html>`;
constructor( private sanitized: DomSanitizer) {}
ngOnInit() {
this.extHtml = this.sanitized.bypassSecurityTrustHtml(this.externFullHtml);
}
}
================================
import {Component, Input, OnInit} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser'
@Component({
selector: 'iframebasedHTML',
template: `
<main>
<div>
<iframe class="embed-responsive-item" [srcdoc]="externFullHtml" allowfullscreen></iframe>
</div>
</main>
`
})
export class ExternHTMLComponent implements OnInit{
extHtml: SafeHtml;
externFullHtml = `
<html>
<meta charset="utf-8">
<head>
</head>
<body>
<div id="fixedContent">
<span> left content </span>
<span> right content </span>
</div>
</body>
</html>`;
constructor( private sanitized: DomSanitizer) {}
ngOnInit() {
this.extHtml = this.sanitized.bypassSecurityTrustHtml(this.externFullHtml);
}
}
No comments:
Post a Comment