没有Http的提供者!错误:没有Http提供商! at injectionError

时间:2017-11-11 09:41:15

标签: angular typescript ionic-framework ionic2 ionic3

未捕获(承诺):错误:没有Http的提供者!错误:没有Http提供商!在injectionError

组件文件:

import { Component,Injectable } from '@angular/core';
import { HttpModule, Http } from '@angular/http';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Camera } from 'ionic-native'
import firebase from 'firebase'

@IonicPage()
@Component({
  selector: 'page-user-main',
  templateUrl: 'user-main.html',
})
export class UserMainPage {
    picdata:any
    picurl:any
    mypicref:any
  public people: any;

  constructor(public navCtrl: NavController, public navParams: NavParams, 
    public alertCtrl: AlertController, public http: Http
     ) {
   // this.films = this.http.get('http://0.0.0.0:3000/');
  }   
}

module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule, Http } from '@angular/http';
import { IonicPageModule } from 'ionic-angular';

@NgModule({
  declarations: [
    UserMainPage,
  ],
  imports: [
    BrowserModule,
    IonicPageModule.forChild(UserMainPage),
    HttpModule
  ]})
export class UserMainPageModule {}

运行时错误 未捕获(承诺):错误:没有Http的提供者!错误:没有Http提供商! at injectionError(http://localhost:8100/build/vendor.js:1788:90)at noProviderError

更新:在App.module.ts中添加提供程序后修复错误

1 个答案:

答案 0 :(得分:1)

根本不建议这样做。您绝不能将HTTP注入您的网页constructor()。它是一个反模式。你需要为此创建一个provider。之后,你可以将该提供者注入你的page

CLI

ionic generate provider MyProvider