title: structuring a utility class in typescript with function currying
body: <p>Updated</p>
  
  <p>So i am creating a function in preCheckService called getData, which i want to call from other components. But for some reason, i am not able to call that function, how can i make getData public function so it can be called from components</p>
  
  <h2>pre-check.service.ts</h2>
  
  <pre><code>import {Component,Injectable} from '@angular/core'
  import {HttpModule, Http} from "@angular/http";
  import 'rxjs/add/operator/map'
  import Util from './Util';
  
  
  @Injectable()
  export class preCheckService{
  
      u:Util;
       mode:string="local";
  
      constructor(private http: Http ){
          this.u = new Util();
      }
      getData(){
          var u =this.u.getPreCheckDefinitions(this.mode);
          return u();
  
      }
  
  }
  </code></pre>
  
  <h2>Util.ts</h2>
  
  <pre><code>import {Injectable} from '@angular/core'
  import {HttpModule, Http} from "@angular/http";
  import {subscribeOn} from "rxjs/operator/subscribeOn";
  
  export default class Util{
      constructor(private http: Http){
      }
  
      getPreCheckDefinitions = type =&gt;{
          switch (type){
              case 'server':
                  return  function getData(){
                      return this.http.post("server/PreCheck/preCheckDefs.do", {radBusLine : 1}).map(
                          (res) =&gt; res.json()
                      )
                  };
              case 'local':
                  return  function getData(){
                      return this.http.get("app/data/preCheckData.json").map(
                          (res) =&gt; res.json()
                      )
                  };
          }
      };
  }
  </code></pre>
  
  <p>and i am getting below error</p>
  
  <pre><code>EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'http' of undefined
  TypeError: Cannot read property 'http' of undefined
  </code></pre>