I am working with Dynamic component creating ( resolveComponentFactory ) so it's working good with static @Input() properties. But for dynamic setter it isn't working.
I can't do that this.componentReference.instance[myPropVar]= someValue
with setter that created inside component.
Is it possible? Thanks!
property setter in my dynamic component is:
@Input() set lockMessage(val: any) {
if (val) {
console.log("Visit details -> ", val);
}
}
it is the same like in that post Angular 2 dynamic component creation
but I want to add some property which have setter to my dynamically created component.
P.S. yes. I tried to set my property to dynamic component with that construction
/**
* public updateSingleComponentProp -> update single prop on component instance
* @param prop {string} -> property name
* @param val {any} -> property value
* @returns {void}
*/
public updateSingleComponentProp(prop: string, val: any): void {
let compInstance = this.componentReference.instance;
compInstance[prop] = val;
if (compInstance.hasOwnProperty(prop) || compInstance.hasOwnProperty('_' + prop))
compInstance[prop] = val;
else
throw new Error("Component doesn't have this property -> " + prop);
}
and it throws an error because that property doesn't exists. I checked the component instance and that setter exists in prototype