我正在做这个教程:https://youtu.be/qs2n_poLarc?list=WL并且正在尝试学习 ionic 框架。
问题是教程(根据我阅读的内容)有点过时了。视频的作者使用了 import { HttpModule } from "@angular/http
,但我在 StackOverflow 上读到我应该使用 import { HttpClient } from "@angular/common/http";
。
问题是当我尝试编译代码时出现此错误:模块“AppModule”导入的意外值“HttpClient”。请添加@NgModule 注释。
。现在我不知道应该在哪里添加它,因为我的 app.module.ts
看起来像这样:
import { NgModule, ErrorHandler } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { IonicApp, IonicModule, IonicErrorHandler } from "ionic-angular";
import { MyApp } from "./app.component";
import { HttpClient } from "@angular/common/http";
import { AboutPage } from "../pages/about/about";
import { ContactPage } from "../pages/contact/contact";
import { HomePage } from "../pages/home/home";
import { TabsPage } from "../pages/tabs/tabs";
import { SettingsPage } from "../pages/settings/settings";
import { StatusBar } from "@ionic-native/status-bar";
import { SplashScreen } from "@ionic-native/splash-screen";
import { WeatherProvider } from "../providers/weather/weather";
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
SettingsPage
],
imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClient], //Added it right here
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
SettingsPage
],
providers: [
StatusBar,
SplashScreen,
{ provide: ErrorHandler, useClass: IonicErrorHandler },
WeatherProvider,
HttpClient
]
})
export class AppModule {}
知道我在这里缺少什么吗?我找到了 this回答,但我在那里找不到解决方案。
最佳答案
这意味着它不承认它是一个模块。试试这个:
import {HttpClientModule} from '@angular/common/http';
关于javascript - 模块 ' ' 导入了意外值 ' '。请添加@NgModule 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48306524/