12

I had an application in angular1 and I was using jquery to load an external page in my HTML element. This is the html of my container element:

<div id="externalContainer" class="text-center">
</div>

I used the following script to load the external page.

$( "#externalContainer" ).load( myExternalPageLink );

Now this doesn't seem to work in angular4, can experts guide me how can I achieve this functionality in angular4?

Iman Bahrampour
  • 6,180
  • 2
  • 41
  • 64
Awais Ashraf
  • 258
  • 1
  • 2
  • 12
  • I know that I am a little late to the party here, but I came across this question while trying to solve my own problem and wanted to share in case someone else had the same issue. I was trying to also allow custom components to be used in our external html for our blog. I documented it all on our [blog (dynamically generate angular components from external html)](https://www.arka.com/blog/dynamically-generate-angular-components-from-external-html). Hopefully this is moderately helpful to the next person who comes across this. – Amos47 May 08 '18 at 20:04

1 Answers1

11

You can use [innerHtml] something like

<div [innerHtml]="myTemplate">
</div>

In your component

export public class MyComponent {
    private myTemplate: any = "";
    constructor(http: Http) {
        http.get(myExternalPageLink).map((html:any) => this.myTemplate = html);
    }
}
jitender
  • 10,238
  • 1
  • 18
  • 44