Skip to content
Closed
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
7 changes: 6 additions & 1 deletion libs/single-spa-angular/internals/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export function getContainerElementAndSetTemplate<T extends BaseSingleSpaAngular
}

const containerElement = getContainerElement(domElementGetter, props);
containerElement.innerHTML = options.template;
if (typeof options.template === 'function') {
const template = options.template as (props: any) => string;
containerElement.innerHTML = template(props);
} else {
containerElement.innerHTML = options.template;
}
return containerElement;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/single-spa-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 | Function;
domElementGetter?: DomElementGetter;
bootstrapFunction(props: AppProps): Promise<NgModuleRef<any> | ApplicationRef>;
}
8 changes: 6 additions & 2 deletions libs/single-spa-angular/src/single-spa-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export function singleSpaAngular<T>(userOptions: SingleSpaAngularOptions<T>): Li
throw Error('single-spa-angular must be passed an options.bootstrapFunction');
}

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

if (NG_DEV_MODE && !options.NgZone) {
Expand Down