Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!