From c4406294966480105af23ee08d2100e4cac4fd0f Mon Sep 17 00:00:00 2001 From: Simone Piccinini Date: Wed, 7 Sep 2022 15:41:31 +0200 Subject: [PATCH] fix(astro-angular): check the component inputs before setting (#81) Related to #79 --- packages/astro-angular/src/client.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/astro-angular/src/client.ts b/packages/astro-angular/src/client.ts index 7b876aa7b..3f25e8333 100644 --- a/packages/astro-angular/src/client.ts +++ b/packages/astro-angular/src/client.ts @@ -1,5 +1,8 @@ import 'zone.js/dist/zone.js'; -import type { ɵComponentType as ComponentType } from '@angular/core'; +import { + reflectComponentType, + ɵComponentType as ComponentType, +} from '@angular/core'; import { ApplicationRef, NgZone, createComponent } from '@angular/core'; import { createApplication } from '@angular/platform-browser'; @@ -17,9 +20,17 @@ export default (element: HTMLElement) => { hostElement: element, }); - if (props) { + const mirror = reflectComponentType(Component); + if (props && mirror) { for (const [key, value] of Object.entries(props)) { - componentRef.setInput(key, value); + if ( + mirror.inputs.some( + ({ templateName, propName }) => + templateName === key || propName === key + ) + ) { + componentRef.setInput(key, value); + } } }