question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

::ng-deep leaks out of component

See original GitHub issue

šŸž bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Not sure

Description

Using ::ng-deep` causes the styles to be applied to elements completely outside of the component’s template. According to the documentation it should only affect elements inside the child’s template and descendant component’s templates.

šŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-oo7twb?file=src%2Fapp%2Fhello.component.ts

šŸ”„ Exception or Error

Notice that all 3 <p> elements are styled with the ::after text. The first one should not get the style.

šŸŒ Your Environment

Angular 7.2.13

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
awalton3commented, Jul 14, 2019

This is still an issue. I’m expecting it to only affect children but it is affecting whole other sections. Why is this closed? And how is this expected behaviour?

What else could we do to get expected behaviour?

Use case: reusable customised table used all over the show. One specific place we use the table can have a smaller min-width because we only show ID and Name, not a bunch of other stuff that requires horizontal scrolling etc. so to set min-width on table, I need to set it on the specific component using the reusable customised table component, not on the table component itself so it doesn’t affect everywhere else.

Looks like you can use :host ::ng-deep instead of ::ng-deep and it works. I had the same problem and this method solved the problem.

1reaction
tiepptcommented, Jul 8, 2019

I’m expecting it to only affect children but it is affecting whole other sections.

@CAspeling you can using following solution

:host ::ng-deep p::after {
    content: ': affected by styles';
}

Output:

[_nghost-nhb-c1] p::after {
    content: ': affected by styles';
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ng-deep changes other components style - css - Stack Overflow
I am using a .md file to display information in a dialog from Material for Angular. The thing is thatĀ ...
Read more >
Angular 10 - Avoid using ::ng-deep (ngdeep)
I found issues when attempting to override stylings mostly for Material Components but, have had my own (parent) components present challengesĀ ...
Read more >
The Dangers Of NG-Deep Bleeding - Upmostly
But hold on, we've heard about this amazing thing called ng-deep that basically removes encapsulation for components in Angular! Let's try it!
Read more >
Angular :host, :host-context, ::ng-deep - The Complete Guide
As we develop a component style suite for an application, we tend to run into situations where the styles from one feature start...
Read more >
There is no alternative to ::ng-deep - Tom Smykowski - Medium
In Angular, like in any other framework, sometimes you have to style a child component based from a parent component.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found