【发布时间】:2017-05-26 10:14:30
【问题描述】:
取决于(布尔)类变量的值,我希望我的ng-content 被包裹在 div 中或不被包裹在 div 中(即 div 甚至不应该在 DOM 中)...最好的方法是什么?我有一个Plunker 尝试这样做,我认为这是最明显的方式,使用 ngIf .. 但它不起作用......它仅显示布尔值之一的内容,而不显示另一个布尔值的内容
请协助 谢谢!
http://plnkr.co/edit/omqLK0mKUIzqkkR3lQh8
@Component({
selector: 'my-component',
template: `
<div *ngIf="insideRedDiv" style="display: inline; border: 1px red solid">
<ng-content *ngIf="insideRedDiv" ></ng-content>
</div>
<ng-content *ngIf="!insideRedDiv"></ng-content>
`,
})
export class MyComponent {
insideRedDiv: boolean = true;
}
@Component({
template: `
<my-component> ... "Here is the Content" ... </my-component>
`
})
export class App {}
【问题讨论】:
-
好plunkr,好问题..搞砸了,也想不通。我很想知道解决方案
标签: angular angular-ng-if angular2-ngcontent