如何编译和评估角度2中的html字符串?

时间:2016-04-05 09:21:17

标签: angular angular2-template

我制作了一个通知组件,其任务是根据传递给其服务的内容显示通知。一切都很好,除了一件事,传递给content的html字符串中的任何指令或绑定事件都不起作用。在这种情况下,(click)="close()不会做任何事情。

以下是我班级的片段:

export class CoreComponent {

  constructor(private _notificationsService: NotificationsService) {
    this._notificationsService.show({content: '<h1 (click)="close()">hello world</h1>'});
  }

  close() {
    alert('closed notification');
  }
}

在通知模板中,我使用[innerHTML]编译内容:

<div [innerHTML]="notification.content"></div>

但这似乎只能编译html,而不是任何点击事件等。

你如何编译所有内容而不仅仅是html?

0 个答案:

没有答案