1

Tengo un Runtime Error con el método get de Http y no se por que, quien me pueda ayudar le agradezco, el error es el siguiente:

Runtime Error Uncaught (in promise): Error: No provider for Http! Error: No provider for Http! at injectionError (http://localhost:8100/build/main.js:1583:86) at noProviderError (http://localhost:8100/build/main.js:1621:12) at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/main.js:3122:19) at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/main.js:3161:25) at ReflectiveInjector.getByKey (http://localhost:8100/build/main.js:3093:25) at ReflectiveInjector.get (http://localhost:8100/build/main.js:2962:21) at AppModuleInjector.get (ng:///AppModule/module.ngfactory.js:220:110) at AppModuleInjector.getInternal (ng:///AppModule/module.ngfactory.js:343:54) at AppModuleInjector.NgModuleInjector.get (http://localhost:8100/build/main.js:3908:44) at resolveDep (http://localhost:8100/build/main.js:11276:45)

los codigos son

src/providers/servi-productos.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the ServiProductos provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class ServiProductos {

  constructor(public http: Http) {
    console.log('Hello ServiProductos Provider');
  }


  getMyJson(){
    this.http.get("assets/json/data.json").map(res => res.json()).subscribe(data => {
        console.log(data);
    });
  }

}

src/app/app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { Perfil } from '../pages/perfil/perfil';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { ServiProductos } from '../providers/servi-productos';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    Perfil,
    ListPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp, {
      //backButtonText: 'Volver',
      iconMode: 'ios',
      modalEnter: 'modal-slide-in',
      modalLeave: 'modal-slide-out',
      tabsPlacement: 'bottom',
      pageTransition: 'ios-transition'
    }),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    Perfil,
    ListPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    ServiProductos,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

src/page/perfil/perfil.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { ServiProductos } from '../../providers/servi-productos';

/**
 * Generated class for the Perfil page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-perfil',
  templateUrl: 'perfil.html',
})
export class Perfil {
    login: {username?: string, password?: string} = {};
  submitted = false;

  constructor(public navCtrl: NavController, public navParams: NavParams, public serviProduct: ServiProductos) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad Perfil');
    this.serviProduct.getMyJson();
  }

}

src/assets/json/data.json

{
 // X contenido data.json
}

1 respuesta 1

1

Los proveedores tienen Http incluido de forma predeterminada, y con el fin de utilizar Http en su aplicación tendrá que agregar el HttpModule a su app.module.ts:1

1
  • Gracias, parece ser correcta la respuesta, pero podría contestarla completamente, agregando lo que falta al código el 4 jul. 2017 a las 21:49

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.