'@ angular/core'의 {Directive, ElementRef, Input, OnInit}을 가져 오십시오. '@ angular/http'의 {Headers, Http, Response}을 가져 오십시오.
@Directive가 ({선택 : 'ngInclude'}) 수출 클래스 NgIncludeDirective이하는 OnInit {
@Input('src')
private templateUrl: string;
@Input('type')
private type: string;
constructor(private element: ElementRef, private http: Http) {
}
parseTemplate(res: Response) {
if (this.type == 'template') {
this.element.nativeElement.innerHTML = res.text();
} else if (this.type == 'style') {
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(res.text()));
head.appendChild(style);
}
}
handleTempalteError(err) {
}
ngOnInit() {
this.
http.
get(this.templateUrl).
map(res => this.parseTemplate(res)).
catch(this.handleTempalteError.bind(this)).subscribe(res => {
console.log(res);
});
}
}을 구현
당신은 [ComponentFactoryResolver]을 찾고 될 수
(https://angular.io/ docs/ts/latest/cookbook/dynamic-component-loader.html)에서 다운로드 할 수 있습니다. – ccpizza