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

355
Visualizações
forkJoin return error You provided 'undefined' where a stream was expected

Previously, I asked an issue about return nested httprequest with wait subrequest.

https://stackoverflow.com/questions/69308614/angular-map-wait-observable-to-complete[Angular map wait Observable to complete]1

I made some changes to it, but it throw error

Error: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Here are my update code

      test2(): Observable<Student[]> {
    return this.test1().pipe(
      mergeMap((result) => {
        if (!result) {
          return of(result);
        }
        return forkJoin(
          result.map((rr) => {
            if (rr.age === 1) {
              rr.age = rr.age * 10;
              return of(rr);
            } else {
              this.client
                .get('https://api.coindesk.com/v1/bpi/currentprice.json')
                .pipe(
                  map((res) => {
                    console.log(res);
                    rr.age = rr.age * 10000;
                    return rr;
                  })
                );
            }
          })
        ).pipe(
          map((paths) => {
            console.log('w');
            console.log(paths);
            return paths;
            // return result.map((e, index) => ({
            //   age: paths[index],
            // }));
          })
        );
      })
    );
  }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The issue in your code is that you are using a condition inside your .map. If you are using a condition in .map function, you need to add return because as the error states that a stream was expected instead of undefined. In order for you to provide an observable, you need to return your observable inside your if-else condition.

In the code below, I added the keyword return on your of() and on your http call. I also created a stackblitz containing my solution for you to check.

test2(): Observable < Student[] > {
  return this.test1().pipe(
    mergeMap((result) => {
      if (!result) {
        return of(result);
      }
      return forkJoin(
        result.map((rr) => {
          if (rr.age === 1) {
            rr.age = rr.age * 10;
            return of(rr);
          } else {
            return this.client
              .get('https://api.coindesk.com/v1/bpi/currentprice.json')
              .pipe(
                map((res) => {
                  console.log(res);
                  rr.age = rr.age * 10000;
                  return rr;
                })
              );
          }
        })
      ).pipe(
        map((paths) => {
          console.log('w');
          console.log(paths);
          return paths;
        })
      );
    })
  );
}
over 4 years ago · Santiago Trujillo 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