I am creating an Ionic2 app. I have a component that I would like to load an external templateUrl into e.x (http:www.example.com/test-view.html).
How do I go about loading that html into the templateUrl variable in @Component?
Here's what I have so far.
import { Component, DynamicComponentLoader, ViewContainerRef,
ViewChild } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { Http, Headers, RequestOptions } from '@angular/http';
@Component({
//templateUrl: 'build/pages/hello-ionic/hello-ionic.html'
template: `<div [innerHTML]="myVal"></div>`,
selector: 'HelloIonicPage'
})
export class HelloIonicPage {
myVal: any;
viewLink: any;
viewHtml: any;
constructor(private http: Http) {
let headers = new Headers({ 'Content-Type': 'text/html' });
let options = new RequestOptions({ headers: headers });
this.viewHtml = this.http.get('http://example.net//test-view1.html');
this.myVal = this.viewLink
console.log(this.myVal);
}
}
You can do it like this:
Note that html will be sanitized, so if you need something fancy you'll have to use DomSanitizationService. Don't forget about it's Security Risk flag in the docs (;