如何在打字稿的公共函数中初始化 Http 导入
How to initialize Http import in public function in typescript?
在下面的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
}
公共属性可通过this
(当前实例)引用访问:
public getAll = function() {
this.http.get(...);
}
相关文章:
- 使用javascript函数在页面初始化后加载jquery
- ember-js组件初始化不同的函数
- 函数无法识别初始化的变量
- 为什么当我使用初始化触发器函数时,我总是找不到脚本函数:发送发票如果新
- 主干模型:初始化与构造函数
- Node.js:如何在服务器初始化时运行一个特殊的函数
- JavaScript初始化函数
- require.js+backbone.js:如何构造具有初始化函数的模块
- 在初始化Javascript时执行的私有函数中设置公共属性
- 使用javascript函数初始化php变量
- JavaScript初始化函数
- 如何在初始化jQuery.ajax成功函数后覆盖它
- 如何初始化一次并将相同的值一次又一次地传递给另一个函数
- 角度测试:监视在控制器初始化时执行的函数
- 使用JavaScript加载函数初始化幻灯片
- Javascript 嵌套函数初始化
- 未定义的函数初始化标签输入引导程序 3.
- 用函数初始化ng-model字符串
- JS中的函数构造函数初始化
- 当使用下划线函数初始化变量时,最好对数组和_(obj)使用.slice(0).克隆对象