我是角度组件中 ViewEncapsulation 的忠实粉丝。但是我看看我们是否将其设置为 ViewEncapsulation.None - 我们也可以仅通过 SCSS 中的组件选择器来封装样式。例如:
my-component {
h1 {}
button {}
etc..
}
另外,如果我想使用一些 material.angular 组件并在 my-component 内部对其进行自定义,则无需封装就更容易和清洁:
当封装打开时:
:host ::ng-deep (which is deprecated) {
mat-expansion-panel {
some-internals {}
}
}
当封装关闭时:
my-component {
mat-expansion-panel {
some-internals {}
}
}
你怎么看?是否有一些参数可以使用封装而不是选择器封装模式?