Gen*_*yuk 4 transclusion angular-template angular
如何在Angular中进行插槽转换而不包括包装标签?
例如:
这是带选择器的组件模板my-component:
<div class="my-component">
<p class="some sensitive css-classes">
<ng-content select="sub-header"></ng-content>
</p>
<p class="more sensitive css-classes">
<ng-content select="sub-footer"></ng-content>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是用数据填充模板的组件之一
<my-component>
<sub-header>
Very <strong>important</strong> text with tags.
</sub-header>
<sub-footer>
More <em>important</em> text with tags.
</sub-footer>
</my-component>
Run Code Online (Sandbox Code Playgroud)
转换结果如下:
<div class="my-component">
<p class="some sensitive css-classes">
<sub-header>
Very <strong>important</strong> text with tags.
</sub-header>
</p>
<p class="more sensitive css-classes">
<sub-footer>
More <em>important</em> text with tags.
</sub-footer>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
由于语义和非常敏感的CSS样式,这不是很有用
如何进行如下所示的转换:
<div class="my-component">
<p class="some sensitive css-classes">
Very <strong>important</strong> text with tags.
</p>
<p class="more sensitive css-classes">
More <em>important</em> text with tags.
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
与其他问题的主要区别在于dom的转换.
您可以ngProjectAs在ng-container标记上使用angular属性
<my-component>
<ng-container ngProjectAs="sub-header">
Very
<strong>important</strong> text with tags.
</ng-container>
<ng-container ngProjectAs="sub-footer">
More
<em>important</em> text with tags.
</ng-container>
</my-component>
Run Code Online (Sandbox Code Playgroud)
有关文档,请查看https://github.com/angular/angular.io/issues/1683
| 归档时间: |
|
| 查看次数: |
3351 次 |
| 最近记录: |