【发布时间】:2018-06-26 15:41:20
【问题描述】:
我正在做这个教程:https://youtu.be/qs2n_poLarc?list=WL 并且正在尝试学习 ionic 框架。
问题是本教程(根据我阅读的内容)有点过时了。视频的作者使用了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 {}
知道我在这里缺少什么吗?我找到了this 的答案,但在那里找不到解决方案。
【问题讨论】:
-
答案有帮助吗?
标签: javascript angularjs typescript ionic-framework