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

287
Visualizações
How to use component A functionalities in component B where both are independent?

I have component A with all functionalities and same needs to be used in component B. Since huge code is written in componentA.ts but not in service so in this case how can make use component A logic without using service where both are independent components.

I saw many post in stack overflow but could not find proper solution.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is a few approaches to achieve your goal:

  1. Helper. If it's some complicated logic you can move it into shared helper class (something like 'shared/***.helper.ts)
  2. Inheritance. You can create parent component with all common logic and inherit it with 'extends' functionality. (You can read more about it here: https://www.bitovi.com/blog/4-reasons-to-fall-in-love-with-angular-component-inheritance) I personally don't think that this is the best practice for frontend, but in some particular cases it might be reasonable.
  3. Service. You said that you don't want to use service for that, but it's actually a valid architectural solution to use services not only for API interactions.
  4. Code duplication. If we are talking about some small functions which describe simple elements behaviour - it's okay to have small pieces of code duplication in different components.
about 4 years ago · Juan Pablo Isaza Relatório
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