Skip to content

Commit 6b50c72

Browse files
feat: register as a custom element
Co-authored-by: Louis Greiner <[email protected]>
1 parent 09d3303 commit 6b50c72

6 files changed

+35
-3
lines changed

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@angular/common": "^17.0.5",
2727
"@angular/compiler": "^17.0.5",
2828
"@angular/core": "^17.0.5",
29+
"@angular/elements": "^17.1.0",
2930
"@angular/forms": "^17.0.5",
3031
"@angular/localize": "^17.0.5",
3132
"@angular/platform-browser": "^17.0.5",

src/app/app.module.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {NgModule} from "@angular/core";
1+
import {NgModule, Injector, ApplicationRef, DoBootstrap} from "@angular/core";
22
import {NgxEditorModule} from "ngx-editor";
33
import {BrowserModule} from "@angular/platform-browser";
4+
import {createCustomElement} from "@angular/elements";
45
import {HTTP_INTERCEPTORS, HttpClientModule} from "@angular/common/http";
56
import {OAuthModule} from "angular-oauth2-oidc";
67
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
@@ -230,10 +231,20 @@ import {ActionMenuComponent} from "./view/action-menu/action-menu/action-menu.co
230231
SbbBreadcrumbModule,
231232
SbbAutocompleteModule,
232233
],
233-
bootstrap: [AppComponent],
234+
bootstrap: environment.customElement ? [] : [AppComponent],
234235
providers: [
235236
... environment.backendUrl ? [{provide: BASE_PATH, useValue: environment.backendUrl}] : [],
236237
{provide: HTTP_INTERCEPTORS, useClass: HttpErrorInterceptor, multi: true},
237238
],
238239
})
239-
export class AppModule {}
240+
241+
export class AppModule implements DoBootstrap {
242+
constructor(private injector: Injector) {}
243+
244+
ngDoBootstrap() {
245+
if (environment.customElement) {
246+
const element = createCustomElement(AppComponent, {injector: this.injector});
247+
customElements.define("sbb-root", element);
248+
}
249+
}
250+
}

src/environments/environment.model.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface Environment {
66
backendUrl?: string;
77
authConfig?: AuthConfig;
88
disableBackend: boolean;
9+
customElement: boolean;
910
}

src/environments/environment.standalone.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const environment: Environment = {
44
production: true,
55
label: "standalone",
66
disableBackend: true,
7+
customElement: true,
78
};

src/environments/environment.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const environment: Environment = {
2424
backendUrl: "http://localhost:8080",
2525
authConfig,
2626
disableBackend: false,
27+
customElement: false,
2728
};
2829

2930
/*

0 commit comments

Comments
 (0)