Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected value ' ' imported by the module ' '. Please add a @NgModule annotation

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.

like image 820
Alex Ironside Avatar asked Jan 17 '18 17:01

Alex Ironside


2 Answers

It means it doesn't recognise it as a module. Try this:

import {HttpClientModule} from '@angular/common/http';
like image 87
Julius Dzidzevičius Avatar answered Sep 25 '22 18:09

Julius Dzidzevičius


It should be HttpClientModule , Change,

From

imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClient],

To

imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClientModule],

make sure you've added

import { HttpClientModule, HttpClient } from '@angular/common/http';
like image 31
Sajeetharan Avatar answered Sep 22 '22 18:09

Sajeetharan