I have the following problem. I have an application constructed using Angular 6 with routing system. I want to create a web component that will contain this application and be able to use it as part on a different web application. I have followed this tutorial and I have modify it based on my needs: https://codingthesmartway.com/angular-elements-a-practical-introduction-to-web-components-with-angular-6/
The result is that nothing renders on the screen and now error exist in the browser Error: The selector "app-root" did not match any elements.
On the browser source files I can confirm that the js file that contains my web component is loaded successfully.
Here is what I have:
In app.module.ts
@NgModule({
declarations: [
AppComponent,
VideoRoomComponent,
DashboardComponent,
StreamComponent,
DialogNicknameComponent,
ChatComponent,
DialogExtensionComponent,
],
imports: [
FormsModule,
ReactiveFormsModule,
BrowserModule,
BrowserAnimationsModule,
MatButtonModule,
MatCardModule,
MatToolbarModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
MatDialogModule,
MatTooltipModule,
AppRoutingModule,
HttpClientModule,
],
entryComponents: [
AppComponent,
DialogNicknameComponent,
DialogExtensionComponent,
],
providers: [{provide: APP_BASE_HREF, useValue: '/'}, MyService],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(private injector: Injector) {}
ngDoBootstrap() {
const el = createCustomElement(AppComponent, { injector: this.injector });
customElements.define('myElement', el);
}
}
Here, my index.html to test the custom element
<!DOCTYPE html>
<html>
<head>
<title>My webpage!</title>
<script>
var global = global || window;
</script>
<script type="text/javascript" src="myElement.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
<myElement></myElement>
</body>
</html>
Any suggestions on this problem?
Thanks in advance