CSS classes not picked up during Angular 5 compilation

核能气质少年 提交于 2019-12-11 05:46:28

问题


I'm using ag-grid in my angular 5 project. I'm trying to add css classes to the cells. Having looked the extensive documentation on ag-grid cell style I have tried to use cellClass and cellClassRules.

The styles are defined in the scss file, as an example:

.readonly-cell{ background-color: #cccccc; }

The scss file is then included in the component:

@Component({
  selector: 'app-volume',
  templateUrl: './volume.component.html',
  styleUrls: ['./volume.component.scss']
})

I then apply the class to the column:

{headerName:'Power', field:'power', width:150, cellClass:'readonly-cell'}

The grid itself is working fine. The issue is that the the power cells do not change colour. When I check the rendered HTML in Firefox, I can see that the cell have indeed have the class readonly-cell applied to them. But the style details are not listed on the rules panel.

This makes me think that the classes are not being picked up during the compilation. I don't think it's an issue with ag-grid, but the way the style classes are being picked up.

Is there any way to troubleshoot why the classes and the definitions are not being included in the compilation?


回答1:


You get that behavior because element you are trying to target by a CSS rule is generated outside your Angular component and Angular adds special attributes so that component CSS applies only to that component (and not to its child components, any DOM nodes added outside Angular etc.). You should either build all the HTML you need to style using Angular and in exactly the same component as your styles, or disable that feature. You can disable it either by using ViewEncapsulation.None:

@Component({
  selector: 'app-volume',
  templateUrl: './volume.component.html',
  styleUrls: ['./volume.component.scss'],
  encapsulation: ViewEncapsulation.None
})

or by using /deep/ in your stylesheet, as described here:

https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep



来源:https://stackoverflow.com/questions/51173268/css-classes-not-picked-up-during-angular-5-compilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!