Skip to content

Instantly share code, notes, and snippets.

@nezhar
Last active February 21, 2018 07:14
Show Gist options
  • Select an option

  • Save nezhar/79ad48078ed1d941710a3e106b79c61a to your computer and use it in GitHub Desktop.

Select an option

Save nezhar/79ad48078ed1d941710a3e106b79c61a to your computer and use it in GitHub Desktop.
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) { }
transform(value: any, args?: any): any {
if (value) {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
}
}
}
**Inside tag:** `<iframe width="560" height="315" [src]="getVideoURL(video.embed) | safe"></iframe>`
**Interpolation:** `{{ getVideoURL(video.embed) | safe }}`
**Note:** Pipe can be generate using angular cli: *ng g pipe path/name*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment