I am building an angular 7 application and dynamically creating components (form controls) at runtime depending on data type.
Following is an excerpt from my dynamically-loading-component.ts file
this.componentRef.instance.form = this.form;
const dynamicComponent = this.componentRef.instance;
I am binding some functions to this dynamicComponent like below:
dynamicComponent.onKeyUp = function (value) {
self.onValueChangeOfControl(dynamicComponent, value);
};
In one of the control types for example, in number.component.html file, I have following code
<input type='number' [value]="metadata.Value" [name]="metadata.Name" [id]="metadata.Name"
(keyup)="onKeyUp($event.target.value)">
Whenever a keyup
event occurs, it correctly calls the globally assigned dynamicComponent.onKeyUp
function and everything works fine locally.
However, when I build this using ng build --prod
it gives me below error -
number\number.component.html(2,3): : Property 'onKeyUp' does not exist on type 'NumberComponent'.
Angular is expecting onKeyUp()
definition in my number.components.ts file however, I have this bounded to dynamic component above. I don't want to write duplicate code in each and every control component file for such events.
What are the options to resolve this? ng build
works fine but I need ng build --prod
to work to get optimized bits to deploy.
Thoughts?