Is there a way to add a CSS class (say .angular-app
) to every single HTML element that Angular (as in Angular 4) adds to the DOM? By "every single HTML element" I also mean cases of children and grand children and so on in the templates as well as transcluded content, i.e. not just Angular components/directives/hosts.
Background: I'm working on a huge monolithic AngularJS project with hundreds of thousands of lines of code (including tens of thousands of lines of CSS). Now, some AngularJS components of the project are supposed to be upgraded to Angular. Unfortunately, a lot of the styles of the surrounding AngularJS project leak into the Angular components and clash with styles we want to use there. One solution we're therefore considering is to add a :not(.angular-app)
selector to every single selector of the AngularJS styles (via SASS or some post-processing Python script), so that they don't match any elements used within the Angular components.
Is there any way to pull this off?
Side note: Obviously this problem could easily be solved by using all: revert
in an Angular component's CSS or by creating a ShadowDOM but since these techniques are barely supported by browsers yet, we need an intermediate solution. (For completeness, yet another solution would be to add a :not()
selector to every selector of the AngularJS stylesheet that makes sure that we're not within an Angular component but this would require CSS 4 selectors.)
[EDIT]: I suppose this could be done by writing a custom renderer for the Angular components (see these links) but I'm not entirely sure how. Are e.g. createElement
and appendElement
used by Angular itself for every HTML element it processes?