Using Angular 2+ [innerhtml] To Add Html Including Style Attributes
I'm using Angular 2+ [innerHTML] input to insert HTML formatting including style tags. In my template I have something like: In my
Solution 1:
You're nearly there. You just need to make sure that you are using your pipe for your HTML string.
Example pipe:
import {Pipe} from'@angular/core';
import {DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl} from'@angular/platform-browser';
@Pipe({
name: 'safe'
})
exportclassSafePipe {
constructor(protected sanitizer: DomSanitizer) {}
transform(htmlString: string): any {
returnthis.sanitizer.bypassSecurityTrustHtml(htmlString);
}
}
Example usage:
<span [innerHTML]="someVar | safe"></span>
Hope this helps!
Post a Comment for "Using Angular 2+ [innerhtml] To Add Html Including Style Attributes"