【发布时间】:2018-02-21 18:50:38
【问题描述】:
我有以下角度来添加动态加载的内容:
main.html
<div class="top">
<ng-template #main></ng-template>
</div>
main.ts
import { Component, ViewChild, ComponentFactoryResolver, ViewContainerRef } from '@angular/core';
@Component({
selector: 'page-main_page',
templateUrl: 'main_page.html'
})
export class main_page {
@ViewChild('main', { read: ViewContainerRef }) entry: ViewContainerRef;
data: any;
constructor(public resolver: ComponentFactoryResolver){
};
ngOnInit(){
this.getDynamicREST().then((res)=>{
this.data = res; //Where it is a html markup from php server: <div class="sample"> Example </div>
const factory = this.resolver.resolveComponentFactory(this.data);
this.entry.createComponent(factory);
})
};
}
在getDynamicRest() 中,我从 php 服务器获取 html 标记,例如:
<div class="sample"> Example </div>
但是我收到一个错误"Error: No component factory found for <div class="sample"> Example </div>"
任何建议将不胜感激。
【问题讨论】:
标签: angular