Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular4 Load external html page in a div

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?

like image 829
Awais Ashraf Avatar asked Oct 10 '17 06:10

Awais Ashraf


People also ask

HOW include external HTML file in Angularjs?

Following is code from angular component to import external html. http. get('assets/included. html', { responseType: 'text' }).


1 Answers

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);
    }
}
like image 122
jitender Avatar answered Oct 12 '22 01:10

jitender