I've created two custom elements using Angular Elements.
<capp-customtag1>
is defined incustomtag1.js
<capp-customtag2>
is defined incustomtag2.js
I load <capp-customtag1>
with <script type="text/javascript" src="assets/customtag1.js"></script>
.
Similarly, for <capp-customtag2>
.
Separately, they work as intended. However, if I try to use both of them in the same project (an Angular 6 project), when I attempt to load the second script, I get the following error:
ERROR DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry.
The calls to CustomElementRegistry are made in customtag1.js
and customtag2.js
.
This is the code I use to create capp-customtag1
in the Angular Element AppModule constructor:
const el = createCustomElement(CustomTag1Component, {injector: this.injector});
customElements.define('capp-customtag1', el);
This is the code to create capp-customtag2
in the second project's AppModule constructor:
const el = createCustomElement(CustomTag2Component, {injector: this.injector});
customElements.define('capp-customtag2', el);
Why do both elements have the same custom element name? And, how can I fix the problem?