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

149
Visualizações
RxJs: merge stream data and a promise

I would like to display users's data and their profile pictures. But I get the basic data and the profile pictures from 2 different services. What I would like to do, is to merge the pictures' url into my tableData.

My code so far:

interface User {
  id: number,
  name: string,
  email: string
}

interface UserWithPicture extends User {
  image: string[] | "",
}

interface ProfileImage {
  id: number,
  url: string
}

  tableData: UserWithPicture[];
  profileImage: ProfileImage[];

Both async functions return array of objects.


async ngOnInit() {
  this.tableData = await this.getUserDataService.fetchUsers().toPromise();
  const userID = this.tableData.map(u => u.userId);

  from(this.userProfilService.getUserProfileImage(userID))
    .pipe(takeUntil(this.destroy$),
      map(userProfileImages => userProfileImages.filter(user => user.id).map(upi => upi.url)))
    .subscribe(data => {
        this.userProfileImage = data;
      }
    })
}

I have tried to add the urls into tableData, but I cannot do that outside the relevant code block, it will always return undefined.

const newArr = this.tableData.map(v => Object.assign(v, {image: this.userProfileImage}))

How can I merge this.userProfileImage into the tableData object of arrays?

about 4 years ago · Juan Pablo Isaza
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