title: Angular TypeScript Undefined result outside function. Send the result like output param
body: <p>Hello please can you help me on this problem I m new in Angular and TS.</p>
  <p>I have a function that I need to send it like an output parameter because in the next step I will call it from other component.
  My problem now that I get the good result only inside the function but outside I get 2undefined.
  I have the commented line  <code>this.tab= result;</code> work but I need to send the result first like a parameter because after i will call this function from other component.</p>
  <p>Thanks in advance.</p>
  <pre><code> export class A implements OnInit {
        tab= [];
  
  
  
      
           ngOnInit(): void {
            this.getResult(this.isDeprecated,this.tab);                     
              console.debug('2'+this.tab);     **//2undefined**
            }
  
  
          
            getResult(isDeprecated: boolean,wl:any) {            
              this.Service1.GetOnly(isDeprecated).subscribe(
                (result) =&gt; {
                  if (result) {
                  // this.tab= result;  **It work**
                     wl= result;
                    console.debug('1'+result);    **//I get result only inside function**          
                  }
                },
                (error) =&gt; {
                  console.log(error);
                }
              );
            }
  </code></pre>