Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import { Pipe, PipeTransform } from '@angular/core';
  2. import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl,
  3. SafeResourceUrl } from '@angular/platform-browser';
  4.  
  5. @Pipe({
  6. name: 'safeDom'
  7. })
  8. export class SafeDomPipe implements PipeTransform {
  9.  
  10. constructor( private domSanitizer:DomSanitizer ){
  11. }
  12.  
  13. public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
  14. switch (type) {
  15. case 'html': return this.domSanitizer.bypassSecurityTrustHtml(value);
  16. case 'style': return this.domSanitizer.bypassSecurityTrustStyle(value);
  17. case 'script': return this.domSanitizer.bypassSecurityTrustScript(value);
  18. case 'url': return this.domSanitizer.bypassSecurityTrustUrl(value);
  19. case 'resourceUrl': return this.domSanitizer.bypassSecurityTrustResourceUrl(value);
  20. default: throw new Error(`Invalid safe type specified: ${type}`);
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement