Reputation: 28046
When I attempt to compile the following typescript class I get the error:
"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);
}
}
Errors:
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'.
Upvotes: 0
Views: 2128
Reputation: 220884
You declared two instance members (_http
, contentHeader
) and then tried to access them from a static method. Static methods obviously can't see instance members (because which instance?).
I think you probably just want to remove static
from those methods.
Upvotes: 1