title: Pass data from one function to another function within same Angular component
body: <p>I am having 2 functions within the same angular component (Am using angular4). I have initialized a string variable as null globally and then I have assigned value to that variable in one function. Now I have to get the value in my second function. But its still taking the initial value "NULL". Can someone help me in fixing this ?</p>
  
  <pre><code>export class AppComponent implements OnInit {
  etag: string = null;
  
  constructor() {}
  ngOnInit(){
      this.getData();
  }
  
  getData(): void {
    this.etag = "t498dgs8";
  }
  
  printData(): void {
   console.log(this.etag);
  }
  }
  </code></pre>