【发布时间】:2017-12-25 17:34:04
【问题描述】:
我正在关注this Angular 关于 Http 的基础教程。
正如在“设置:安装模块”部分中看到的那样,他们导入 HttpClientModule 如下:
import {HttpClientModule} from '@angular/common/http';
当我在我的项目中尝试这个时,我收到以下错误:“找不到模块'@angular/common/http'”。
我尝试过导入以下模块,如下:
import { HttpModule } from '@angular/http';
然后是我的导入部分:
imports: [
HttpModule
],
现在的问题是,我无法将此 HttpModule 注入到我的服务对象中,并且出现以下错误:“找不到模块 HttpModule”。
这是我的服务类:
import { Injectable, OnInit } from '@angular/core';
//Custom Models
import { Feed } from '../Models/Feed';
@Injectable()
export class FeedsService {
constructor(private httpClient: HttpModule) {}
}
我做错了什么?
更新
当我意识到我无法按照教程导入模块时,我应该做的就是运行npm update 命令来更新我的所有包。
【问题讨论】:
-
查看this answer了解
Http和HttpClient之间的区别 -
在 Angular 11 上我解决了这个问题,删除 node_modules 文件夹并运行
npm install
标签: angular node-modules