【问题标题】:How to edit css of child component imported from other module Angular 2+如何编辑从其他模块Angular 2+导入的子组件的css
【发布时间】:2018-07-13 09:14:05
【问题描述】:

我使用来自amg-snazzy-window的agm-snazzy-window

有解释说我可以覆盖 css 类,但是当我这样做时它不起作用。 这是我的例子:

地图组件.html

   <agm-snazzy-info-window [closeWhenOthersOpen]="true">
         <ng-template>
            My snazzy window
         </ng-template>
   </agm-snazzy-info-window>

我想拥有更广泛的内容,所以我做了这个: 地图组件.scss:

.si-content {
  width: 500px !important;
}

我做错了什么?

【问题讨论】:

  • 你需要使用::ng-deep

标签: css angular sass


【解决方案1】:
::ng-deep .si-content {
  width: 500px !important;
}

这将告诉 Angular 将正确的 ViewEncapsulation.Emulated 类附加到您的样式中。默认情况下它不会这样做,因为它无法在您的模板中找到它们。

没有::ng-deep,你的风格将是.si-content[_ngcontent-1],或类似的东西。在这种情况下,[_ngcontent-1] 来自map-component。使用 ::ng-deep 指示 Angular 寻找“更深”以找到正确的组件 agm-snazzy-info-window

【讨论】:

  • 所以默认情况下它应该只是.si-content 但是现在它找不到一些类或模块?
  • 我更新了答案,希望对您有所帮助。最好检查带有和不带有 ::ng-deep 的开发工具中的代码,以查看差异以及发生了什么...
  • 它已被弃用,并且正在从主要浏览器和工具中删除支持。因此,Angular 中的支持(对于 /deep/、>>> 和 ::ng-deep 的所有 3 个)将被删除。在此之前 ::ng-deep 应该是首选,因为它与工具的兼容性更广泛。 angular.io/guide/component-styles#deprecated-deep--and-ng-deep
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2018-11-20
  • 2019-05-29
  • 2017-07-02
  • 2019-11-19
  • 1970-01-01
  • 2021-07-16
相关资源
最近更新 更多