我正在做这个教程: https ://youtu.be/qs2n_poLarc?list=WL 并且正在尝试学习离子框架。
问题是教程(从我读到的)有点过时了。视频的作者使用了 import { HttpModule } from "@angular/http
,但我在 StackOverflow 上读到我应该使用 import { HttpClient } from "@angular/common/http";
。
问题是当我尝试编译代码时出现此错误: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.
。现在我不知道应该在哪里添加它,因为我的 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 {}
知道我在这里缺少什么吗?我找到 了这个 答案,但在那里找不到解决方案。
原文由 Alex Ironside 发布,翻译遵循 CC BY-SA 4.0 许可协议
这意味着它不将其识别为模块。尝试这个: