作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在下面的 Typescript 代码中,我想调用一个需要导入的函数。我可以在类的构造函数中初始化导入,但是如何在公共(public)函数中执行此操作?
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)属性可通过this
(当前实例)引用访问:
public getAll = function() {
this.http.get(...);
}
关于javascript - 如何在 typescript 的公共(public)函数中初始化Http导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34962617/
我是一名优秀的程序员,十分优秀!