Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Create factory with resolver.resolveComponentFactory fails when using directive more than once at the same page

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();
        }
      )
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!