Skip to content

Commit

Permalink
feat: register as a custom element
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jun 27, 2024
1 parent 1215875 commit 7977c4a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@angular/common": "^17.0.5",
"@angular/compiler": "^17.0.5",
"@angular/core": "^17.0.5",
"@angular/elements": "^17.1.0",
"@angular/forms": "^17.0.5",
"@angular/localize": "^17.0.5",
"@angular/platform-browser": "^17.0.5",
Expand Down
17 changes: 14 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {NgModule} from "@angular/core";
import {NgModule, Injector, ApplicationRef, DoBootstrap} from "@angular/core";
import {NgxEditorModule} from "ngx-editor";
import {BrowserModule} from "@angular/platform-browser";
import {createCustomElement} from "@angular/elements";
import {HTTP_INTERCEPTORS, HttpClientModule} from "@angular/common/http";
import {OAuthModule} from "angular-oauth2-oidc";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
Expand Down Expand Up @@ -230,10 +231,20 @@ import {ActionMenuComponent} from "./view/action-menu/action-menu/action-menu.co
SbbBreadcrumbModule,
SbbAutocompleteModule,
],
bootstrap: [AppComponent],
bootstrap: environment.customElement ? [] : [AppComponent],
providers: [
... environment.backendUrl ? [{provide: BASE_PATH, useValue: environment.backendUrl}] : [],
{provide: HTTP_INTERCEPTORS, useClass: HttpErrorInterceptor, multi: true},
],
})
export class AppModule {}

export class AppModule implements DoBootstrap {
constructor(private injector: Injector) {}

ngDoBootstrap() {
if (environment.customElement) {
const element = createCustomElement(AppComponent, {injector: this.injector});
customElements.define("sbb-root", element);
}
}
}
1 change: 1 addition & 0 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export interface Environment {
backendUrl?: string;
authConfig?: AuthConfig;
disableBackend: boolean;
customElement: boolean;
}
1 change: 1 addition & 0 deletions src/environments/environment.standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const environment: Environment = {
production: true,
label: "standalone",
disableBackend: true,
customElement: true,
};
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const environment: Environment = {
backendUrl: "http://localhost:8080",
authConfig,
disableBackend: false,
customElement: false,
};

/*
Expand Down

0 comments on commit 7977c4a

Please sign in to comment.