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

106
Visualizações
Angular Promise returns undefined in another component

this is my carComponent.ts it has following method:

async Download() {
    try {
      const settings = {
        kit: true,
        tyres: true,
        serviced: false,
      };
      const [kits, tyres] = await Promise.all([
        this.checkKits(
          conf,
          "A",
         100,
          false,
          "My kit"
        ),
        this.checktyres(100, 50, false, 'My tyres'),
      ]);
    
    const checkSvg= [...kits.slice(0, 4), ...tyres, ...kits.slice(4)];
   checkSvg.forEach(({ side, svg }) => {
     console.log(svg); // here it returns all the SVG data; works 100%
   return svg;
    });
  }
  catch(e) {
    console.error(e);
  }
   
}

this is viewCarsComponent.ts which is calling above method. But here promise returns undefined so can anyone help please to resolve my issue? I am not sure what am I doing wrong or what I need to do here to resolve.

async DisplaySVG() {
 await this.carComponent.Download().then(data =>{
  console.log(data);
  // here it is undefined... 
 }).catch(error =>{
   console.log(error)
 });

  }

Thank you

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

0

You currently have no return statement in Download, so it by default the promise resolves to undefined. If you want to return an array of all the kits and tyres, then simply return checkSvg:

const checkSvg = [...kits.slice(0, 4), ...tyres, ...kits.slice(4)];
return checkSvg;

If each of these have a .svg property, and you only want those, then create a new array with just the .svg properties, and return that:

const checkSvg = [...kits.slice(0, 4), ...tyres, ...kits.slice(4)];
const svgsOnly = checkSvg.map(({ svg }) => svg);
return svgsOnly;
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