Support for ViewEncapsulation.ShadowDom now available in Edge, Internet Explorer, and legacy browsers

I am working with Angular 7 and material design. Some of my components utilize ShadowDOM ViewEncapsulation, leading to errors in older versions of IE, Edge, Chrome, and Firefox.

Below is the error message I am encountering:

Object doesn't support property or method 'attachShadow'

I have already included default polyfills but the error persists.

/**
 * This file contains essential polyfills required by Angular and must be loaded before the application.
 * Additional polyfills can be added here.
 *
 * The file is divided into two sections:
 *   1. Browser polyfills: These are applied prior to loading ZoneJS and are categorized based on browsers.
 *   2. Application imports: Files imported after ZoneJS that need to be loaded before your main file.
 *
 * The current configuration is for "evergreen" browsers; recent versions that update automatically. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more at https://angular.io/guide/browser-support
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */


/** IE9, IE10 and IE11 require all the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

/**
 * For applications indexed by Google Search, this is necessary.
 * Googlebot uses a renderer based on Chrome 41.
 * https://developers.google.com/search/docs/guides/rendering
 **/
import 'core-js/es6/array';

/** IE10 and IE11 need the following for NgClass support on SVG elements */
// import 'classlist.js';  // Run `npm install --save classlist.js`.

/** Reflect API is required for IE10 and IE11. */
import 'core-js/es6/reflect';

/**
 * Web Animations `@angular/platform-browser/animations`
 * Only if AnimationBuilder is used within the app and using IE/Edge or Safari.
 * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
 **/
// import 'web-animations-js';  // Run `npm install --save web-animations-js`.

/**
 * By default, zone.js will patch all possible macroTask and DomEvents
 * parts of macroTask/DomEvents patch can be disabled by setting flags below
 */

 // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
 // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
 // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames

 /*
 * In IE/Edge developer tools, addEventListener will also get wrapped by zone.js
 * with flag below, it will bypass `zone.js` patch for IE/Edge
 */
// (window as any).__Zone_enable_cross_context_check = true;

/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.


/***************************************************************************************************
 * APPLICATION IMPORTS
 */

Answer №1

After some testing, I discovered that the key to enabling support for ViewEncapsulation.ShadowDOM in IE and Edge is simply adding the ShadyDOM polyfill. The polyfill can be found at this link, where I sourced it from. By including the following script tag in my index.html:

<script src="https://cdnjs.cloudflare.com/ajax/libs/shadydom/1.1.0/shadydom.min.js"></script>
, I was able to successfully enable support for ViewEncapsulation.ShadowDOM in both IE and Edge.

In a previous comment, I noted that adding a reference to WebComponentsJs only worked in Edge. However, using the shadydom polyfill proved effective in enabling support for both IE and Edge browsers.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic loading of locale in Angular 5 using Angular CLI

Angular 5 offers a solution for loading i18n locale dynamically using registerLocaleData https://angular.io/guide/i18n#i18n-pipes I am interested in loading the locale based on a dynamic setting, such as one stored in localStorage. I tested loading a sin ...

Tips for obtaining type narrowing for a function within a mixed array

In my coding adventure, I have crafted a brilliant match function. This function is designed to take a value along with an array of [case, func] pairs. The value is then compared to each case, and if a match is found, the associated func is executed with t ...

The integration of Angular 6 with AngularJS components fails to load properly in a hybrid application

Currently, I am in the process of upgrading a large AngularJS version 1.7.3 to a hybrid app using Angular 6. The initial phase involved converting all controllers/directives into an AngularJS component. Subsequently, I created a new Angular 6 project skele ...

What is the best way to create an interface tailored to a specific scenario using TypeScript?

In my TypeScript project without React, I am dealing with an interface structured like this: export interface LayerStyling<T> { attribute: string; value: AllowedTypes; type: LayerTypes; layout?: { icon: string }; state ...

Issues with unresponsive buttons in AngularJs

In creating a basic registration page, I encountered a strange issue with the button functionality. Whenever I attempt to submit the form, an error should be logged to the console. However, the buttons on the registration page appear to be inactive - it se ...

Creating Concurrent Svelte Applications with Local State Management

Note: Self-answer provided. There are three primary methods in Svelte for passing data between components: 1. Utilizing Props This involves passing data from a parent component to a child component. Data transfer is one-way only. Data can only be passed ...

How can you inform TypeScript about a file that will be included using a script tag?

I am currently utilizing TypeScript for my front-end JavaScript development, and I have a situation where I am loading two scripts from my index.html file as shown below: <script src="replacements.js"></script> <script src="socket.js">&l ...

Can you identify the specific syntax for a 'set' function in TypeScript?

I have a TypeScript function that looks like this: set parameter(value: string) { this._paremeter = value; } It works perfectly fine. For the sake of completeness, I tried to add a type that specifies this function does not return anything. I experimen ...

Creating an SCSS class in a component that is customizable and can

After doing some research and reading various guides and blogs, I am still struggling to find the right solution for this issue. Imagine having the following classes in your main styles.scss file: .btn { padding: 5px; text-transform: uppercase; } .b ...

Using conditional buttons with ngSwitch in conjunction with ngFor to render a list of buttons from an asynchronously pip

I can't seem to figure out a logic error I am experiencing. Apart from the issue with my code, why does Angular restrict me from doing this? The purpose of using the conditional switch is to have drop-down menus for different models such as Gender. I ...

Ensuring Angular2 Javascript is validating only numerical input and not accepting characters

Access the full project here (excluding nodes_modules): Note: After running the project, all actions related to this issue can be found in the "Edit All" section of the website. Click on that to view the table. The main objective of this website section ...

`Is There a Solution When Compilation Fails?`

I keep encountering an issue when I run the command npm start. The problem seems to be originating from PancakeSwap Frontend and after several attempts, I am still unable to resolve it. Your assistance is greatly appreciated :) Below is a snippet of my Ap ...

Set up your Typescript project to transpile code from ES6 to ES5 by utilizing Bable

Embarking on a new project, I am eager to implement the Async and Await capabilities recently introduced for TypeScript. Unfortunately, these features are currently only compatible with ES6. Is there a way to configure Visual Studio (2015 Update 1) to co ...

Looking for a regular expression to require either a dollar sign ($) or a percentage symbol (%) but not

At the moment, I currently have this input field set up on an HTML page within my Angular 9 application: <input type="text" formControlName="amountToWithholdInput" onkeyup="this.value = this.value.replace(/[^0-9.%$]/, &ap ...

What are some effective methods for resetting a state in @ngrx/store?

Lately, I've been grappling with a problem that's been on my mind for the past few days. Our team is developing an Angular 2 application, and my task involves creating a wizard for users to complete a form. I've successfully set up the dat ...

My Angular component seems to have a mind of its own, constantly refreshing itself and causing me

I'm facing an issue with a view that loads another component using routing. Here is the code that triggers the loading: <a href="/productDetails/{{product.ProductId}}">{{product.Name}}</a> Below is the div where the other component (prod ...

Issues with Angular's Material UI CDK Virtual Scroll Viewport functionality not functioning as intended

While following the official documentation here to set up a virtual viewport, an error message appeared in the HTML component: Error message 'cdk-virtual-scroll-viewport' is not a recognized element: 1. If 'cdk-virtual-scroll-viewport' ...

What could be the reason behind the absence of this.props.onLayout in my React Native component?

In my React Native app, I have the below class implemented with Typescript: class Component1 extends React.Component<IntroProps, {}> { constructor(props){ super(props) console.log(props.onLayout) } ... } The documentation for the View ...

Issue with NullInjectorError: Failure to provide a custom component - Attempting to add to providers without success

I keep encountering errors during my test attempts... Despite looking into similar issues, I am still facing problems even after adding my custom LoginComponent to app.module.ts providers. It is already included in the imports section. app.module.ts @Ng ...

The identifier 'before' could not be located

While working with jest and typescript, I encountered an issue when using "before" calls: Cannot find name 'before'.ts(2304) I made sure to have @types/jest installed already. Update: It appears that jest does not have a "before" function - it ...