-4

How to convert url to secure url link that can be recognized by iframe in angular

  <iframe src="{{url}}"></iframe>
Khaled Ayed
  • 1,121
  • 3
  • 12
  • 29
  • Check this answer (to possible duplicate question) https://stackoverflow.com/a/38037914/2050306 – robert May 29 '19 at 13:41
  • Possible duplicate of [Angular 6 iframe binding](https://stackoverflow.com/questions/52382608/angular-6-iframe-binding) – SiddAjmera May 29 '19 at 13:48

1 Answers1

1

Try like this below

secure-pipe.ts

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';

@Pipe({ name: 'secure' })
export class SecurePipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
} 

app.module.ts

@NgModule({
   declarations : [
     ...
     SecurePipe
   ],
})

In Html

<iframe [src]="url | secure"></iframe>
Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76