What to use in place of ::ng-deep

后端 未结 7 880
梦毁少年i
梦毁少年i 2020-11-22 10:42

I\'m trying to style an element placed by the router outlet in angular and want to make sure that the element generated gets a width of 100%

From most of the replies

7条回答
  •  日久生厌
    2020-11-22 11:03

    The simple and easy alternative to a deep style is a common style using the element selector of the parent component. So if you had this in hero-details.component.css:

    :host ::ng-deep h3 {
      font-style: italic;
    }
    

    It would become this in styles.css:

    app-hero-details h3 {
      font-style: italic;
    }
    

    Basically a deep style is an un-encapsulated style so it conceptually seems more like a common style to me than a component style. Personally I would not use deep styles anymore. Breaking changes are normal in major version updates and deprecated feature removal is fair game.

提交回复
热议问题