我在使用Angular2时遇到了问题,当我创建服务并将其添加到appModule
的providers:[]
部分时,出现了错误:
Uncaught TypeError: Cannot set property 'stack' of undefined
at SyntaxError.set [as stack] (eval at <anonymous> (http://localhost:8080/vendor.js:94:2), <anonymous>:1628:63)
at assignAll (eval at <anonymous> (http://localhost:8080/polyfills.js:2217:2), <anonymous>:704:29)
我做过两个应用程序,以前从未遇到过类似的错误......这是我的简单服务文件:
Injectable()
export class RecordService {
private API_END_POINT: string = 'app/records';
private API = process.env.API_END_POINT;
constructor(private http: Http ) {
}
getRecords(): Observable<any> {
return this.http
.get( this.API_END_POINT )
.map( (res:Response) => res.json().data as RecordModel )
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
我不知道如何修复这个问题,也没有任何有关此错误的信息...请帮帮我!
Injectable()
应该改为@Injectable()
。你是否将HttpModule
添加到了imports: [...]
中? - Günter Zöchbauer