Multiple Angular Elements from different scripts

2019-03-03 19:44发布

Is it possible to use Angular Elements generated from diffrent scripts?

I have 2 projects weather-widget and clock widget which generates their own script(concated all required ones).

When I use these widgets individually it works fine but when these are used on same page it gives error shown as below:

DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry
at CustomElementRegistry.define (http://172.27.147.64:8080/node_modules/document-register-element/build/document-register-element.js:2:18538)
at new AppModule (http://172.27.147.64:8080/dist/weather-widget/main.js:115:24)

2条回答
孤傲高冷的网名
2楼-- · 2019-03-03 20:12

The feature to have multiple angular micro apps on the same page is currently not supported.

The error that you see actually describes the issue well. When you load your second micro app, bootstrap will run and try to bootstrap the module by calling it's ngDoBootstrap method. If you do some detailed logging though, you will notice that it tries to invoke ngDoBootstrap on the first micro app for the second time. If you want to make this work, you would need to do some manual work to control the bootstrap process yourself and make sure to bootstrap the correct module when it is introduced on the page.

Resource

查看更多
爷、活的狠高调
3楼-- · 2019-03-03 20:21

Use a unique tag name to define your Angular Element. That should prevent this issue.

查看更多
登录 后发表回答