javascript - Neočakávaná hodnota ' ' importovaná modulom ' '. Prosím pridajte anotáciu @NgModule
Robím tento tutoriál: https://youtu.be/qs2n_poLarc?list=WL a snažím sa naučiť framework Ionic.
Problém je, že tutoriál je (z toho, čo som čítal) trochu zastaraný. Autor videa použil import { HttpModule } from "@angular/http", ale čítal som na StackOverflow, že by som mal použiť import { HttpClient } from "@angular/common/http";.
Problém je, že keď sa pokúsim skompilovať kód, dostanem túto chybu: Neočakávaná hodnota 'HttpClient' importovaná modulom 'AppModule'. Prosím, pridajte anotáciu @NgModule.. Teraz nemám tušenie, kam ju mám pridať, pretože môj app.module.ts vyzerá takto:
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 {}
Máte nejakú predstavu, čo mi tu chýba? Našiel som túto odpoveď, ale riešenie tam nemôžem nájsť.
Odpoveď č. 1
To znamená, že to nerozpoznáva ako modul. Skúste toto:
import {HttpClientModule} from '@angular/common/http';
Odpoveď č. 2
Malo by to byť HttpClientModule, Zmeňte,
Z
imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClient],
To
imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClientModule],
uistite sa, že ste pridali
import { HttpClientModule, HttpClient } from '@angular/common/http';
