我想应用角度分量
import { Component } from '@angular/core'
import { DialogService } from './dialog/dialog.service'
@Component({
selector: 'app-root',
templateUrl: '<div></div>',
})
export class AppComponent {
dialogs: any;
constructor(public dialogService: DialogService) {
dialogs = dialogService.getDialogs();
// dialogs are like following =
// { "id": 1, "name": "D1", component: "<x-component>…</x-component>" },
}
}
对话框服务获取包含组件html的JSON数据。如何在现有组件上添加此(<x-component>
)组件?
答案 0 :(得分:0)
将返回的组件从JSON分配给变量
this.returnedComponent = myComponent
然后将其放入HTML
<div [innerHtml]="returnedComponent"></div>