【发布时间】:2019-05-20 17:07:33
【问题描述】:
我使用的是 Angular 7,我有这个文件夹结构
src
app
app.component.css
app.component.html
app.component.spec.ts
app.component.ts
app.module.ts
component.service.spec.ts
component.service.ts
在我的 src/app/component.service 文件中,我有
import { Injectable } from '@angular/core';
import { HttpModule } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class ComponentService {
private apiUrl = 'http://localhost:8080/todo/';
constructor(private http: Http) {
}
findAll(): Promise<Array<AppComponent>> {
return this.http.get(this.apiUrl + "/list")
.toPromise()
.then(response => response.json() as Todo[])
.catch(this.handleError);
}
...
但我反复收到导入错误
ERROR in src/app/component.service.ts(9,29): error TS2304: Cannot find name 'Http'.
我在我的服务中包含了 HttpModule,那么我还缺少什么才能正确包含它?
【问题讨论】:
标签: angular http import httpmodule