Angular 5-@ angular / common / httpclient模块无法导入服务

时间:2019-02-23 07:20:08

标签: angular5 httpclient

我通过如下更新package.json中的依赖项将Angular 6降级为Angular 5:

{
  "name": "angular5-example",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "5.2.0",
    "@angular/compiler": "5.2.0",
    "@angular/core": "5.2.0",
    "@angular/forms": "5.2.0",
    "@angular/platform-browser": "5.2.0",
    "@angular/platform-browser-dynamic": "5.2.0",
    "@angular/router": "5.2.0",
    "core-js": "2.4.1",
    "ngx-clipboard": "^11.1.9",
    "rxjs": "^5.5.6",
    "zone.js": "0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "~6.2.5",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  }
}

并将httpclientmodule添加到app.module.ts文件

import { HttpClientModule } from '@angular/common/http';

我还添加了导入模块文件的部分

 imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule
],

此后,我尝试将HttpClient导入服务文件中的一个,但是即使在输入VS Code时也不会被导入,也无法理解“ common”。

请有人建议降级6至5角以及降级后如何使用HttpClient

预先感谢您的帮助。

0 个答案:

没有答案