angular - PrimeNG - 如何更改单个组件的 p 表中 pTemplate ="caption"的样式

标签 angular sass primeng ng-template p-table

我想更改 p-table 的标题单元格的背景颜色仅在一个组件中,我该怎么办?

我试过<ng-template pTemplate="caption" class="myStyle">

.myStyle{ background: rgb(9,169,121) !important; } 在 my.component.scss 中

但它不起作用。

帮帮我吧!谢谢!


编辑:终于可以了!我看到了@Antikhippe的答案,但我必须添加

:host ::ng-deep { #myTable {
.p-datatable-thead{ background: red;
} .p-datatable .p-datatable-thead > tr > th { background: inherit; } } }

最佳答案

pTemplate="caption" 仅适合表头的一部分,您必须使用 p-datatable-header 类:

试试这个:

:host ::ng-deep {
  #myTable {
    .p-datatable-header {
      background-color: red;
    }
  }
}

我用 #myTable 包围 p-datatable-header 类,仅将此 CSS 应用于具有 myTable id 的表格:

<p-table id="myTable" [value]="products">

参见StackBlitz

关于angular - PrimeNG - 如何更改单个组件的 p 表中 pTemplate ="caption"的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64720375/

相关文章:

html - 固定元素问题 - 无法使其可滚动

javascript - 我可以使用 JavaScript 切换暗模式吗?

lazy-loading - PrimeNG 首次使用延迟加载表设置页面

javascript - Angular:动态更改伪类中的 SCSS 属性

javascript - 为什么 $event 绑定(bind)在使用 PrimeNG 的 RowGroup 表上不起作用?

angular - PrimeNG 不适用于 angular2 cli?

angular - 在 Angular 通用应用程序的查看页面源中看不到标题和元标记

angular - 带有 Angular 6 的 ionic 4 路由

javascript - ng2-dnd : Error: StaticInjectorError(AppModule)[SortableComponent -> ElementRef]:

angular - Angular2 网格的 Kendo UI : add row form on bottom instead of top of list