Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
May 19, 2023
For displaying an HTML from an external URL, you can do the following steps.
constructor(private http: HttpClient, private sanitizer: DomSanitizer) {}
   2. Get the HTML from your URL as a response using the httpClient module.
this.http.get(“url”, {responseType: “text”}).subscribe(response => { this.displayHTML = this.sanitizer.bypassSecurityTrustHtml(response); })
   3. Assign the displayHTML to the innerHTML property of your div element.
<div [innerHTML]=”displayHTML”></div>
Alternatively, you can also create a pipe for sanitizing the HTML if you are using the external URL at multiple places.
import { Pipe, PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({name: 'safeHtml'}) export class SafeHtml implements PipeTransform { constructor(private sanitizer:DomSanitizer){} transform(html) { return this.sanitizer.bypassSecurityTrustStyle(html); } }
On the HTML side, use this pipe to sanitize your HTML.
<div [innerHTML]=”displayHTML | safeHtml”></div>