意想不到的价值' '由模块导入' &#39 ;.请添加@NgModule注释

时间:2018-01-17 17:11:45

标签: javascript angularjs typescript ionic-framework

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

问题是教程(从我读到的)有点过时了。该视频的作者使用了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回答,但我找不到那里的解决方案。

3 个答案:

答案 0 :(得分:4)

应该 if(isset($_GET['sg'])){ if($_GET['sg'] == "member") { echo "m is set!"; } if($_GET['sg'] == "admin") {{ echo "a is set!"; } if($_GET['sg'] == "operator"){ echo "op is set!"; } } ,更改,

HttpClientModule

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

确保您已添加

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

答案 1 :(得分:3)

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

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

答案 2 :(得分:0)

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