Issue
I'm doing this tutorial: https://youtu.be/qs2n_poLarc?list=WL and am trying to learn ionic framework.
The problem is the tutorial is (from what I read) a little outdated. Author of the video used the import { HttpModule } from "@angular/http
, but I read on StackOverflow that I should use import { HttpClient } from "@angular/common/http";
.
The problem is when I try to compile the code I get this error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.
. Now I have no idea where I should add it, because my app.module.ts
looks like this:
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 {}
Any idea what I'm missing here? I found this answer but I cannot find the solution there.
Solution
It means it doesn't recognise it as a module. Try this:
import {HttpClientModule} from '@angular/common/http';
Answered By - Julius Dzidzevičius
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.