我对Angular很新,现在已经停留了一段时间。我正在尝试创建一个从内部webapi获取数据的服务,它之前有效,但现在它给出了一个我无法解决的错误。希望你们其中一个人可以帮助我...... 服务:
import {Injectable} from "@angular/core";
import {Http} from '@angular/http';
import 'rxjs/add/operator/toPromise';
import {GraphData} from './graph-data';
@Injectable
export class GraphDataService {
private dataApiUrl = 'app/graph-data';
constructor(private http: Http) {}
getGraphData() : Promise<GraphData[]> {
return this.http.get(this.dataApiUrl)
.toPromise()
.then(response => response.json().data as GraphData[])
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('an error occurred', error); // only for demo
return Promise.reject(error.message || error);
}
}
编译为js时出错:
app/graph-data.service.ts(11,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
Supplied parameters do not match any signature of call target.
答案 0 :(得分:10)
你的装饰师应该是这样的:
@Injectable()
必须使用括号