如何在现有应用程序中添加Angular组件html?

时间:2019-09-17 07:56:26

标签: angular angular7

我想应用角度分量

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>)组件?

1 个答案:

答案 0 :(得分:0)

将返回的组件从JSON分配给变量 this.returnedComponent = myComponent

然后将其放入HTML

<div [innerHtml]="returnedComponent"></div>