I have successfully created a widget using Angular elements that works well in HTML. However, I am unsure of how to export it as a module for use in other Angular, React, Vue web applications. I want to be able to import
import { acmaModule } from package-name
instead of const acmaModule = require('widge.js')
.
In my Angular code:
export class AppModule {
initWidget(options: any){
console.log('options received', options)
}
constructor(private injector: Injector) {
// Expose Window function
(<any>window).acmeWidget = { initWidget: this.initWidget };
// Survey Widget
const surveyComp: any = createCustomElement(SurveyComponent, { injector: this.injector });
customElements.define('acme-survey', surveyComp);
}
ngDoBootstrap() {}
}
And in the HTML file:
<html>
....
<script src="../survey-widget.js">
<script>
acmeWidget.initWidget({
test: "Hello world"
})
</script>
....
</html>