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

204
Visualizações
how to access data outside observable

how can I access or get the value of this.dealType outside this.trasactionService.transactionEvent$. suscription ? . I wanted to access the data and value ofthis.dealType outside , maybe someone can help.

it has value inside the this.trasactionService.transactionEvent$.subscrib but I want to access it outside , I tried logging it using console logs its empty

Thank you, appreciated.

#code

export class DealsApprovalComponent implements OnInit {
  dealType: string;
  totalDealsForApproval = 0;
  constructor(
    private dealService: DealService,
    private notificationService: NotificationService,
    private trasactionService: TransactionService,
    private route: Router,
    private dealTransactionService: DealTransactionService
    
  ) 
  { 
  }
  ngOnInit(): void {
    this.trasactionService.transactionEvent$.subscribe((data) => {
      if(data) {
        switch (data['operation']) {
          case 'deal/deal-type':
          this.dealType = data["dealType"];
          break;
        }
      }
      },
      (error) => {}
    );

    console.log("this.dealType" , this.dealType)
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The console log shows empty because it is executed first before the code inside the subscribe method. If you need to do something with "this.dealType", you can just create a method after you assigned it like so.

ngOnInit(): void {
  this.trasactionService.transactionEvent$.subscribe((data) => {
    if(data) {
      switch (data['operation']) {
        case 'deal/deal-type':
          this.dealType = data["dealType"];
          this.doSomething();
          break;
      }
    }
    },
    (error) => {}
  );
}

private doSomething() {
  console.log(this.dealType);
}

Also, remember to unsubscribe when needed to avoid memory leaks.

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