Javascript 如何在typescript的公共函数中初始化Http导入?

Javascript 如何在typescript的公共函数中初始化Http导入?,javascript,typescript,Javascript,Typescript,在下面的Typescript代码中,我想调用一个需要导入的函数。我可以在类的构造函数中初始化导入,但是如何在公共函数中初始化呢 import {Http} from "angular2/http"; export class AppComponent { constructor( properties. public http: Http ) { this.http.get(...){} //FUNCTION 1: this function works fi

在下面的Typescript代码中,我想调用一个需要导入的函数。我可以在类的构造函数中初始化导入,但是如何在公共函数中初始化呢

import {Http} from "angular2/http";

export class AppComponent {

  constructor( properties.
    public http: Http
    ) {
      this.http.get(...){} //FUNCTION 1: this function works fine

      this.getAll(); //this does not work as FUNCTION 2 does not work
    }

 public getAll = function(){ //FUNCTION 2: this function does not work (cannot find name'http')
      http.get(...){} 
    }

 public otherfunction = function(){
      this.getAll(); //this does not work as FUNCTION 2 does not work
 }

公共属性可通过
(当前实例)引用访问:

public getAll = function() {
  this.http.get(...); 
}