[英]How to style nested components in Angular 6?
Imagine I have a wrapper component: 想象一下,我有一个包装器组件:
<app-my-wrapper>
<router-outlet></router-outlet>
</app-my-wrapper>
The router outlet injects one of following components: 路由器出口注入以下组件之一:
<app-page1></app-page1>
<app-page2></app-page2>
<app-page3></app-page3>
I want app-page1
, app-page2
and app-page3
to have some special styles, but only if inside app-my-wrapper
. 我想要
app-page1
, app-page2
和app-page3
有一些特别的款式,但只有当里面app-my-wrapper
。
I'd normally do something like this: 我通常会做这样的事情:
my-wrapper.component.scss 我-wrapper.component.scss
:host ::ng-deep .page {
/* some styles */
}
According to angular.io , /deep/
, >>>
, and ::ng-deep
are deprecated. 根据angular.io ,不推荐使用
/deep/
, >>>
和::ng-deep
。
What would be the proper way of giving the children components some extra styles depending on the parent component? 根据父级组件,为子级组件提供一些额外样式的正确方法是什么?
You can disable view encapsulation for your current component: 您可以为当前组件禁用视图封装:
Simply add encapsulation: ViewEncapsulation.None
in your component decorator. 只需在组件装饰器中添加
encapsulation: ViewEncapsulation.None
。
See https://angular.io/api/core/ViewEncapsulation for more details. 有关更多详细信息,请参见https://angular.io/api/core/ViewEncapsulation 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.