当我尝试编译以下typescript类时,我收到错误:
"use strict";
import { Http, Headers } from '@angular/http';
const remote: string = 'http://localhost:3000';
export class ApiEndpoint {
public contentHeader: Headers = new Headers({"Content-Type": "application/json"});
constructor(private _http: Http) {}
static signup(payload) {
let url = `${remote}/auth/signup`;
return this._http.post(url, JSON.stringify(payload), {headers: this.contentHeader});
}
static checkUsername(username) {
let url = `${remote}/auth/checkUsername/${username}`;
return this._http.get(url);
}
}
错误:
17): Error TS2339: Property '_http' does not exist on type 'typeof ApiEndpoint'.
TypeScript error:(12,73): Error TS2339: Property 'contentHeader' does not exist on type 'typeof ApiEndpoint'.
TypeScript error: /(17,17): Error TS2339: Property '_http' does not exist on type 'typeof ApiEndpoint'.
答案 0 :(得分:1)
您声明了两个实例成员(_http
,contentHeader
),然后尝试从静态方法访问它们。静态方法显然无法看到实例成员(因为哪个实例?)。
我想您可能只想从这些方法中删除static
。