Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

::ng-deep going to be deprecated - Any alternatives?

Tags:

angular

Doc says:

The shadow-piercing descendant combinator is deprecated and support is being removed from major browsers and tools. As such we plan to drop support in Angular (for all 3 of /deep/, >>> and ::ng-deep). Until then ::ng-deep should be preferred for a broader compatibility with the tools.

Since i want to upgrade to new versions without changing the code, whats are the alternatives for the deprecated methods?

like image 475
Omtechguy Avatar asked Apr 16 '18 14:04

Omtechguy


People also ask

Is Deep deprecated?

[Deprecation] /deep/ combinator is deprecated and will be a no-op in M60, around August 2017.

Why we should not use Ng-deep?

Angular's API states that the ng-deep psuedo-class is deprecated. completely disables view-encapsulation for that rule. If we use it without the :host pseudo-class, it will make the style-rule global, not a good thing. There's something odd about Angular view encapsulation which gets style specificity wrong.

What does :: ng-deep means?

::ng-deep selector Use the ::ng-deep shadow-piercing descendant combinator to force a style down through the child component tree into all the child component views. The ::ng-deep combinator works to any depth of nested components, and it applies to both the view children and content children of the component.


1 Answers

After scouring through the actual notes from the committee meetings on this stuff, it doesn't look like there is an alternative put forward yet. Using the ::ng-deep syntax ensures that you let Angular take care of breaking out of the style encapsulation (for DOM nodes in child components in your template) that they are doing for your styles (and not using browser native features, making it more future-proof obviously). I think that note is just to let you know that whenever the actual browser mechanism is put in place they plan on implementing it. I personally wouldn't shy away from using it tho.

The only way forward without using that operator in your CSS is to completely opt out of letting Angular manage the style encapsulation for your component by doing this:

import { ViewEncapsulation } from '@angular/core';  @Component({     ...     encapsulation: ViewEncapsulation.None }) 

If you do this, your styles become global though, so make sure you prepend each style rule with your component to make sure that they don't leak beyond that. For example, if you have a MyCustomComponent component with a selector of my-custom-component:

my-custom-component button { ... } /* good */ button { ... } /* bad */ 
like image 77
Daniel W Strimpel Avatar answered Oct 23 '22 06:10

Daniel W Strimpel