Ale*_*ide 8 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 {}
Run Code Online (Sandbox Code Playgroud)
知道我在这里缺少什么吗?我找到了这个答案,但我找不到那里的解决方案.
这意味着它无法将其识别为模块。尝试这个:
import {HttpClientModule} from '@angular/common/http';
Run Code Online (Sandbox Code Playgroud)
应该是HttpClientModule更改
从
imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClient],
Run Code Online (Sandbox Code Playgroud)
至
imports: [BrowserModule, IonicModule.forRoot(MyApp), HttpClientModule],
Run Code Online (Sandbox Code Playgroud)
确保您已添加
import { HttpClientModule, HttpClient } from '@angular/common/http';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17825 次 |
| 最近记录: |