【发布时间】:2017-01-24 15:37:38
【问题描述】:
我想提供仅在内容未被嵌入时才会出现的默认内容。
例如这是我的组件模板:
<article>
<header>
<ng-content select="[header]"></ng-content>
</header>
<section>
<ng-content></ng-content>
</section>
</article>
我可以这样使用它:
<my-component>
<h1 header>This is my header</h1>
<p>This is my content</p>
</my-component>
现在,如果我想提供一个默认标题怎么办。是否可以;没有杂技,比如检查ngAfterContentInit中的内容?
【问题讨论】:
-
看看这个答案stackoverflow.com/a/38692980/373655。不确定是否存在不需要
ngAfterContentInit的更优雅的解决方案 -
另外,你能给投影起别名吗?
<ng-content class=".for-parent" select=".for-me">
标签: angular