【发布时间】:2017-01-30 09:07:24
【问题描述】:
我的问题是,当我使用 innererHtml 绑定时 - angular2 删除所有样式属性。这对我很重要,因为在我的任务中 - html 是在服务器端生成的,具有所有样式。 示例:
@Component({
selector: 'my-app',
template: `
<input type="text" [(ngModel)]="html">
<div [innerHtml]="html">
</div>
`,
})
export class App {
name:string;
html: string;
constructor() {
this.name = 'Angular2'
this.html = "<span style=\"color:red;\">1234</span>";
}
}
但在 DOM 中,我只看到 1234,而且这个文本不是红色的。
http://plnkr.co/edit/UQJOFMKl9OwMRIJ38U8D?p=preview
谢谢!
【问题讨论】: