我目前正在尝试将 Angular 2 与 Ionic 2 结合使用,所以我对 TypeScript 有点陌生。基本上我是在实现一个 RESTService,我想使 Rest 类抽象。
export abstract class RESTService{
mHttp: Http;
mParameters: Parameter[];
mURL: string;
constructor (private http: Http, private parameters: Parameter[]){
this.mHttp = http;
this.mParameters = parameters;
}
// URL of the Rest Service
abstract getURL() : string;
// Convert or handle the Response
handleResponse(rawResponse: Response){
let body = rawResponse.json();
return body.data || { };
}
// Handle an error
abstract handleError(error: any);
// Do the rest call
makeCall(): Observable<any> {
return this.mHttp.get(this.mURL).map(this.handleResponse).catch(this.handleError);
}}
这是从 RESTService 扩展的类:
export class RESTServiceJourney extends RESTService{
constructor(http:Http, parameters:Parameter[]){
super(http, parameters);
}
// URL of the Rest Service
getURL() : string {
return "";
}
// Convert or handle the Response
private handleResponse(rawResponse: Response){
return "";
}
// Handle an error
private handleError(error: any){
return "";
}}
但我总是在“export class RESTServiceJourney extends RESTService”。我通过 Google 和 Stackoverflow 进行了搜索,但不知道这是哪种错误。 (我在Stackoverflow上找到了一个,但是那个版本有问题。)
提前致谢!
最佳答案
我在导入抽象类的时候犯了一个错误。
我写道:从 'restService' 导入 { RESTService };
但必须:从 './restService' 导入 { RESTService };
关于angular - typescript 错误 : Type 'any' is not a constructor function type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40169479/