Javascript 如何使用/创建动态模板来编译具有Angular 8的动态组件?

Javascript 如何使用/创建动态模板来编译具有Angular 8的动态组件?,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,这个问题有点类似于读到相同内容的问题,但它是针对Angular 2的,这里给出的解决方案在这一点上是过时的,那里的方法现在甚至不存在。所以基本上我的问题是这个 我正在从服务加载HTML,HTML附带如下链接: ,所以现在我有了一个动态组件,但我不知道如何加载HTML作为其模板并使其正确呈现。(现在模板呈现为字符串文字) 我尝试使用[innerHTML]将HTML传递到静态模板,首先使用信任内容的设置对其进行清理,但这也不起作用,解释了HTML和样式,但链接不起作用 最相关的代码如下所示: @Co

这个问题有点类似于读到相同内容的问题,但它是针对Angular 2的,这里给出的解决方案在这一点上是过时的,那里的方法现在甚至不存在。所以基本上我的问题是这个

我正在从服务加载HTML,HTML附带如下链接:

,所以现在我有了一个动态组件,但我不知道如何加载HTML作为其模板并使其正确呈现。(现在模板呈现为字符串文字)

我尝试使用[innerHTML]将HTML传递到静态模板,首先使用信任内容的设置对其进行清理,但这也不起作用,解释了HTML和样式,但链接不起作用

最相关的代码如下所示:

@Component({
  selector: 'app-content-info',
  templateUrl: './content-info.component.html',
  styleUrls: ['./content-info.component.css']
})
export class ContentInfoComponent implements OnInit {
  @Input() info: ContenInfo;

  @ViewChild(ContentInfoDirective,{static:true}) cInfoD: ContentInfoDirective;

  constructor(private componentFactoryResolver: ComponentFactoryResolver) { }

  ngOnInit() {
    this.loadComponent();
  }

  loadComponent() {
    const Item = this.info;
    const componentFactory = this.componentFactoryResolver.resolveComponentFactory(Item.component);

    const viewContainerRef = this.cInfoD.viewContainerRef;
    viewContainerRef.clear();
    const componentRef = viewContainerRef.createComponent(componentFactory);
    (<AdComponent>componentRef.instance).data = Item.data;
  }

}
@组件({
选择器:“应用程序内容信息”,
templateUrl:'./content info.component.html',
样式URL:['./content info.component.css']
})
导出类ContentInfoComponent实现OnInit{
@Input()信息:ContenInfo;
@ViewChild(ContentInfoDirective,{static:true})cInfoD:ContentInfoDirective;
构造函数(专用componentFactoryResolver:componentFactoryResolver){}
恩戈尼尼特(){
这个.loadComponent();
}
loadComponent(){
const Item=this.info;
const componentFactory=this.componentFactoryResolver.resolveComponentFactory(Item.component);
const viewContainerRef=this.cInfoD.viewContainerRef;
viewContainerRef.clear();
const componentRef=viewContainerRef.createComponent(componentFactory);
(componentRef.instance).data=Item.data;
}
}
我从Angular文档站点(ad banner.component.ts)修改了这个,但是标准文档没有说明如何动态添加模板

所以基本上我需要知道的是如何在Angular 8中的这个动态组件中注入/插入带有(单击)事件的HTML模板,以使事件工作


有效的答案将立即被标记为正确。

然后您必须添加编译器HI prisar,您能提供一个如何执行此操作的示例吗?如果行得通,我会立即把你的答案标为正确答案。