Angular2 styling issues caused by DOM attributes _ngcontent-* vs. _nghost-*

前端 未结 3 1463
一整个雨季
一整个雨季 2020-12-24 07:46

I have an issue with scss and the cli: angular adds an attribute _nghost-fyw-1 to the apps tag (component) during runtime. at the same time it adds an attribute

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 08:08

    update

    It's ::ng-deep since a while.
    See also the comments below.

    original

    You didn't provide too much details where you add your styles and what elements you target with the selectors.

    The "official" way if you want styles to cross element boundaries is to use >>> like

    :host >>> h1 {
      background-color: red;
    }
    
    • :host targets the current element.
    • >>> (or /deep/) makes Angular ignore _nghost-xxx attributes which is used for component style encapsulation emulation.

    See also Styles in component for D3.js do not show in angular 2

提交回复
热议问题