我尝试通过ng-content包含组件中包含的css for children元素.它似乎尚未在Angular 2中实现,或者除了将css放在一般样式表中之外,有人可能有解决方案?
app.component.ts
<comp-parent> <comp-child></comp-child> </comp-parent>
compParent.component.html
<div class="wrapper"> <ng-content></ng-content> </div>
compParent.component.css
.wrapper > comp-child { margin-right: 5px; <-- Not applied !!! }
解决方法
您可以使用/ deep /(已弃用)或>>>或:: ng-deep选择器:
https://angular.io/guide/component-styles#deprecated-deep–and-ng-deep
例如.:
.wrapper ::ng-deep comp-child { ... }
请注意,>>>似乎不适用于基于angular-cli的项目.