0

I do have html content comes from the API.
How do I display it with iframe ?

Something like { ..., template: "<h3 style="margin: 0px; padding: 0px; ..." ...}

Please provide demo if possible.

Thanks.

1
  • Hi, could you please provide more information with your question? At the current state, it's unclear what you are trying to ask. Commented Mar 13, 2018 at 5:54

1 Answer 1

1

Create a pipe for iframe

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(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
} 

And in the component

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

HTML

<iframe width="100%" height="300" [src]="url | safe"></iframe>

You can refer this Plunker

For Angular1.x Plunker

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, can it be same with angular 1 ?
@BHARGAV It is for angular 2 or higher
How can I do the same with Angular 1.x
I've seen that link before but it is not up to my expectation, as I said, It comes from the API which have array objects with JSON html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.