Skip to content

Commit

Permalink
fix: setInput works in real env
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-peruzzo committed Feb 10, 2025
1 parent 62ade89 commit 912d9e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions projects/angular-email/src/lib/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Render = {
cssFilePaths?: string[];
/** path or configuration object */
tailwindConfig?: string | Partial<Config>;
signalInputsPrefix?: string;
};
};

Expand All @@ -33,7 +34,7 @@ type Render = {
* @returns {Promise<string>} The rendered HTML or plain text.
*/
export const render = async ({ component, selector, props, options }: Render) => {
const normalizedHtml = await renderNgComponent(component, selector, props);
const normalizedHtml = await renderNgComponent(component, selector, props, options?.signalInputsPrefix);
const html = applyHtmlTransformations(normalizedHtml, options?.cssFilePaths);
if (options?.plainText) {
return renderAsPlainText(html);
Expand Down Expand Up @@ -72,15 +73,20 @@ const renderAsPlainText = (markup: string) => {
* @param selector - The CSS selector for the component.
* @returns A promise that resolves to the rendered HTML string.
*/
const renderNgComponent = async (component: Type<unknown>, selector: string, props?: Record<string, any>) => {
const renderNgComponent = async (
component: Type<unknown>,
selector: string,
props?: Record<string, any>,
signalInputsPrefix?: string,
) => {
const bootstrap = async () => {
const appRef = await bootstrapApplication(component, {
providers: [provideExperimentalZonelessChangeDetection(), provideServerRendering()],
});
appRef.components.forEach((componentRef) => {
Object.entries(props ?? {}).forEach(([key, value]) => {
if (key in componentRef.instance) {
componentRef.instance[key] = value;
if (key in componentRef.instance || `${signalInputsPrefix ?? ''}${key}` in componentRef.instance) {
componentRef.setInput(key, value);
}
});
componentRef.changeDetectorRef.detectChanges();
Expand Down

0 comments on commit 912d9e8

Please sign in to comment.