title: Why does this variable always return null ? Angular Service
body: <p>Its now 8 hours trying to solve a trivial issue &amp; I can't believe it !</p>
  
  <p>here below a script of angular service </p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  
  @Injectable({
    providedIn: 'root'
  })
  export class GetStockDataService {
  
    constructor(public http:HttpClient) { }
  
  
    RequestData={"query":"{\n  stock{\n    history{\n      \n      low\n      high\n      demand\n    }\n  }\n}"}
  
  getstockdata(){
    return this.http.post('http://localhost:3000/',this.RequestData)
  }
  
  }
  </code></pre>
  
  <p>and here is a component script which is calling that service</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { GetStockDataService } from '../services/get-stock-data.service';
  import { Platform } from '@ionic/angular';
  
  
  
  
  @Component({
    selector: 'app-Stocks',
    templateUrl: 'Stocks.page.html',
    styleUrls: ['Stocks.page.scss']
  })
  
  export class StocksPage implements OnInit {
  
    constructor(private GetStockData:GetStockDataService , private platform : Platform) {}
  
    res:any
  
    ngOnInit(){
  
      this.getdata().subscribe(data=&gt;{this.res=data});
      console.log(this.res)
  
    }
    getdata(){
      return this.GetStockData.getstockdata() }}   
  </code></pre>
  
  <p>WHY the "res" variable is always returning NULL ???? 
  knowing that when I put the console log the variable inside there in the function in the subscription part .. it returns data 
  but I can't make this variable global ... how could I do that ? I just want to get the data from the subscription to the "res" variable to use it the HTML file later .</p>