title: How take value from async method in typescript?
body: <p>I need to call/subscribe to the external service observable method and take value from it. I try it, it component constructer but always return undefined. I examine put console.log inside the method the value is there. need some expert helpt to take this object -&gt;string value in angular.</p>
  <pre><code>     this.x:string; 
          constructor(
          private readonly socService: ocService) { }
      
          
        ngOnInit(): void {
         
      
          this.ocService.getActiveoc().subscribe(oc =&gt; { this.x= oc.id });
          
          //TODO For Testing
          if(this.x){
            console.log(&quot;ID&quot; + this.x)
            this.store.dispatch(selectPatientAction({ x: this.x}));
          }
        }
  
     onScanX() {
      this.store.dispatch(scanX({x: this.x }));
      this.isocSelected = true;
    }
  </code></pre>