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

267
Visualizações
How can I get value from subscribe?

I tried to do this, but it doesn't work. Any help is appreciated thanks!

    export class OuterClass {
    let isEffectiveUrl = (url:string) => {
            let tmpRes:boolean
            this.http.get(url).subscribe((result) => {
                  tmpRes = Object.keys(result).length > 0;
                });
            return tmpRes;
          }
     }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're setting isEffectiveUrl to be a function, not the resulting evaluation. One way to do this would create a local variable and then execute your http.get within a function or one of your lifecycle hooks.

e.g.

export class OuterClass {

  isEffectiveUrl: boolean = false;

  testUrl(url: string): void {
    this.http.get(url).subscribe((result) => {
      this.isEffectiveUrl = Object.keys(result).length > 0;
    });
  }

}

Just remember, this is a reactive model. So what's being run in the subscribe block is asynchronous.

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