我使用Visual Studio创建了一个新项目,并将其从angular4升级到angular6。升级后,我面临”错误:找不到模块“ @ angular / common / http”“
尝试导入 httpclientmodule 但没有运气
package.json
{
"name": "AppShippingNotice",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"@angular/animations": "6.1.0",
"@angular/common": "6.1.0",
"@angular/compiler": "6.1.0",
"@angular/compiler-cli": "6.1.0",
"@angular/core": "6.1.0",
"@angular/forms": "6.1.0",
"@angular/http": "6.1.0",
"@angular/platform-browser": "6.1.0",
"@angular/platform-browser-dynamic": "6.1.0",
"@angular/platform-server": "6.1.0",
"@angular/router": "6.1.0",
"@ngtools/webpack": "6.1.2",
"@types/chai": "4.1.4",
"@types/jasmine": "2.8.8",
"@types/webpack-env": "1.13.6",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^3.0.0",
"awesome-typescript-loader": "5.2.0",
"bootstrap": "4.1.3",
"chai": "4.1.2",
"css": "2.2.3",
"css-loader": "1.0.0",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.12",
"expose-loader": "0.7.5",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.11",
"html-loader": "0.5.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "3.1.0",
"jquery": "3.3.1",
"json-loader": "0.5.7",
"karma": "2.0.5",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.2",
"karma-webpack": "3.0.0",
"preboot": "6.0.0-beta.4",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.12",
"rxjs": "^6.2.2",
"style-loader": "0.21.0",
"to-string-loader": "1.1.5",
"typescript": "3.0.1",
"url-loader": "1.0.1",
"webpack": "4.16.3",
"webpack-hot-middleware": "2.22.3",
"webpack-merge": "4.1.4",
"zone.js": "0.8.26"
},
"dependencies": {
"ng2-completer": "^2.0.8",
"ng2-smart-table": "^1.3.5",
"rxjs-compat": "^6.2.2"
}
}
App.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import { ShipLogComponent } from './components/shiplog/shiplog.component';
import { Ng2SmartTableModule } from 'ng2-smart-table';
@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
CounterComponent,
FetchDataComponent,
HomeComponent,
ShipLogComponent
],
imports: [
CommonModule,
BrowserModule,
HttpClientModule,
FormsModule,
Ng2SmartTableModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'ShipLog', component: ShipLogComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: '**', redirectTo: 'home' }
])
]
})
export class AppModuleShared {
}
我的componenet
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AppService } from '../../services/appservices';
import { shippingnotice } from './shiplog.modal';
import { Ng2SmartTableModule } from 'ng2-smart-table';
@Component({
selector: 'ShipLog',
templateUrl: './shiplog.component.html',
providers: [AppService]
//styleUrls: ['./app/components/request/request.component.css']
})
export class ShipLogComponent implements OnInit
{
constructor(public userService: AppService, http: HttpClient) { }
public ArrApiLi: shippingnotice[];
public GridData: any;
public errorMessage: string;
settings = {
columns: {
id: {
title: 'ID'
},
name: {
title: 'Full Name'
},
username: {
title: 'User Name'
},
email: {
title: 'Email'
}
}
};
data = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz"
},
{
id: 2,
name: "Ervin Howell",
username: "Antonette",
email: "Shanna@melissa.tv"
},
// ... list of items
{
id: 11,
name: "Nicholas DuBuque",
username: "Nicholas.Stanton",
email: "Rey.Padberg@rosamond.biz"
}
];
ngOnInit() {
// this.userService.getApiList().subscribe(data => { console.log(data); this.ArrApiLi = data; });
}
}
每当我运行该应用程序时,它将显示错误。 HTTPModule已经声明并导入。
需要帮助!!!