I have a full Angular 16 application, containing routing, multiple components and services and I need to convert it into a single Webcomponent, that can be loaded via the script tag in an external UI application/shell.
So far, all the tutorials and resources I have come across demonstrate transforming just a single component Angular app into a Webcomponent using Angular Elements, such as this example -
import { Injector, NgModule } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import {HttpClientModule} from "@angular/common/http";
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing. Module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home. Component';
@NgModule({
declarations: [
AppComponent,
HomeComponent
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent, HomeComponent]
})
export class AppModule {
constructor(private injector: Injector) {
const el = createCustomElement(HomeComponent, {injector: this. Injector});
customElements.define('element-home', el);
}
ngDoBootstrap() {}
}
Here, I have a single component in the Angular app, called HomeComponent, from which I can create a Webcomponent titled <element-home>. This can be loaded, as an example, into an HTML page this way -
<body>
<element-home></element-home>
<script src="...." /> // bundled Angular javascript files
</body>
But, how do I transform a complete Angular app (with routing) into a Webcomponent? My angular component structure looks like this -
- AppComponent
<router-outlet>
|
- HomeComponent // for /home route
- DetailComponent // for /detail route
- DetailService
Additionally, any tutorials/resources/guides on this topic would be appreciated!