I have been playing around with Angular Elements and trying to achieve the best browser compatibility possible. However I seem to have hit a dead end, since when I add an IE polyfill for Shadow DOM, it breaks the Element in chrome.
Initially I had the error 'Failed to construct HTML element', so I changed the 'target' in my tsconfig.json to es2015/es6.
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Component
// @dynamic
@Component({
selector: 'flexybox-cardmanagement',
templateUrl: './card-management.component.html',
styleUrls: ['./card-management.component.scss'],
encapsulation: ViewEncapsulation.ShadowDom
})
Changing the target happened to break IE though, since es2015/es6+ is not supported. So I happened to find the custom-elements-es5-adapter in the @webcomponents package, which wraps ES5 to provide the neccessary ES6 functionality to the browsers that needs it. And then I also had to add support for custom-elements.
polyfills.ts
/*****************************************************************************************
* APPLICATION IMPORTS
*/
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js';
import '@webcomponents/custom-elements/custom-elements.min';
At this point it works in Chrome but i get the following error in IE
SCRIPT438: Object doesn't support property or method 'attachShadow'
So I tried adding polyfill for Shadow DOM by adding the following to my polyfills.ts:
import '@webcomponents/shadydom';
Which seems to fix the issue in IE, but now gives me the following error in chrome:
Uncaught TypeError: Cannot read property 'defineProperties' of undefined