1

按照示例从http://valor-software.com/ng2-bootstrap/使用 ng2-bootstrap 生成选项卡视图,我有以下代码:

<tabset>
<tab *ngFor="#tabz of tabs"
     [heading]="tabz.title"
     [active]="tabz.active"
     (select)="tabz.active = true"
     (deselect)="tabz.active = false"
     [disabled]="tabz.disabled"
     [removable]="tabz.removable"
     (removed)="removeTabHandler(tabz)">
    {{tabz?.content}}
</tab>

但我想从 {{tabz?.content}} 属性中提取 HTML 代码。有没有办法做到这一点?我的标签数组如下所示:

public tabs:Array<any> = [
{title: 'Summary View', content: 'Dynamic content 1', active: true},
{title: 'Search View', content: '<someAngularComponent>Error Displaying Entry view</someAngularComponent >'}];
4

2 回答 2

2
<tabset>
<tab *ngFor="#tabz of tabs"
     [heading]="tabz.title"
     [active]="tabz.active"
     (select)="tabz.active = true"
     (deselect)="tabz.active = false"
     [disabled]="tabz.disabled"
     [removable]="tabz.removable"
     (removed)="removeTabHandler(tabz)"
     [innerHTML]="tabz?.content">
</tab>

您应该知道 Angular 不会清理 HTML,也不会以任何其他方式处理它。通过这种方式添加的 HTML,Angular 会忽略, [], (),{{}}等绑定。<my-comp><div myDirective>

于 2016-04-15T05:31:52.213 回答
1

纯html注入:

<tab [innerHTML]="tabz?.content">

Angular2 模板/组件不能像上面一样注入,你可以将内容包装到组件中并使用事件DynamicComponentLoader触发加载它(select)

于 2016-04-15T07:55:07.097 回答