Javascript 模块“ ”导入的意外值“ ”。请添加@NgModule 注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48306524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:04:35  来源:igfitidea点击:

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

javascriptangularjstypescriptionic-framework

提问by Alex Ironside

I'm doing this tutorial: https://youtu.be/qs2n_poLarc?list=WLand am trying to learn ionic framework.

我正在做这个教程:https: //youtu.be/qs2n_poLarc?list=WL并且我正在尝试学习离子框架。

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";.

问题是教程(从我读到的)有点过时了。视频的作者使用了import { HttpModule } from "@angular/http,但我在 StackOverflow 上读到我应该使用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.tslooks like this:

问题是,当我尝试编译的代码,我得到这个错误: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 {}

Any idea what I'm missing here? I found thisanswer but I cannot find the solution there.

知道我在这里缺少什么吗?我找到了这个答案,但在那里找不到解决方案。

回答by Julius Dzidzevi?ius

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

这意味着它不会将其识别为模块。尝试这个:

import {HttpClientModule} from '@angular/common/http';

回答by Sajeetharan

It should be HttpClientModule, Change,

应该是HttpClientModule,改变,

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';

回答by vishal jhorar

you need to replace HttpClient with HttpClientModule and don't change import part. Because HttpClientModule access many part of HttpClient

您需要用 HttpClientModule 替换 HttpClient 并且不要更改导入部分。因为 HttpClientModule 访问了 HttpClient 的很多部分