Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/navbar/src/main.single-spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const lifecycles = singleSpaAngular({
const platformRef = platformBrowser(provideSingleSpaPlatform());
return bootstrapApplication(AppComponent, appConfig, { platformRef });
},
template: '<navbar-root />',
template: () => '<navbar-root />',
NgZone: 'noop',
Router,
NavigationStart,
Expand Down
6 changes: 5 additions & 1 deletion libs/single-spa-community-angular/internals/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ export function getContainerElementAndSetTemplate<T extends BaseSingleSpaAngular
);
}

// If the template is a function, we call it with the props to get the string template.
const template =
typeof options.template === 'function' ? options.template(props) : options.template;

const containerElement = getContainerElement(domElementGetter, props);
containerElement.innerHTML = options.template;
containerElement.innerHTML = template;
return containerElement;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/single-spa-community-angular/internals/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApplicationRef, NgModuleRef } from '@angular/core';
export type DomElementGetter = (props: any) => HTMLElement;

export interface BaseSingleSpaAngularOptions {
template: string;
template: string | ((props: AppProps) => string);
domElementGetter?: DomElementGetter;
bootstrapFunction(props: AppProps): Promise<NgModuleRef<any> | ApplicationRef>;
}
4 changes: 2 additions & 2 deletions libs/single-spa-community-angular/src/single-spa-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function singleSpaAngular<T>(userOptions: SingleSpaAngularOptions<T>): Li
throw Error('single-spa-angular must be passed an options.bootstrapFunction');
}

if (typeof options.template !== 'string') {
throw Error('single-spa-angular must be passed options.template string');
if (typeof options.template !== 'string' && typeof options.template !== 'function') {
throw Error('single-spa-angular must be passed options.template string or function');
}

if (!options.NgZone) {
Expand Down
Loading