When I have 1 instance of my directive at my HTML page, everything works great. But when I use the same directive at the same page more than once, I get error on the creation of the component template the directive use.
Seems like this line of code fails in creating the factory:
private myDirective: ComponentRef<MyComponentContainer>;
...
const factory = this.resolver.resolveComponentFactory(MyComponentContainer); // fails
this.myDirective= this.viewContainerRef.createComponent(factory); // not run at all
MyComponentContainr is just a component with simple template.
What is wrong?
The error is when I try to do something like that:
this.myDirective.instance.top = 10;
// EXCEPTION: Error in :0:0 caused by: Cannot read property 'instance' of undefined
I think the problem is when I use a service inside the directive:
this.MyService.dataUpdated.subscribe
(
(data: Dimension) => {
this.callFunc();
}
)