Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda