0
votes

I am trying to implement a http request in ionic framework 3.1 application. I have created a provider named apidata using ionic g provider apidata command after which i created the following function in it that calls the api and logs the data returned by it on console.

  getremotedata(){
console.log(this.http.get('https://reverie.oiamigotech.com/wp-json/wc/v2/products/?consumer_key=ck_xyz&consumer_secret=cs_xyz'));
  }

and have also imported the http package in the header as import { Http } from '@angular/http';

after which I updated the app.module.ts file to import the provider as import { ApidataProvider } from '../providers/apidata/apidata'; and also added the same to the provider list as providers: [ StatusBar, SplashScreen, {provide: ErrorHandler, useClass: IonicErrorHandler}, ApidataProvider ]

now when i try to call the same from the home page after importing the package and using the following function and constructor definition

constructor(public navCtrl: NavController,public ApidataService: ApidataProvider) {
  }
  ionViewDidLoad(){
    this.ApidataService.getremotedata();
  }

It generated the following error Uncaught (in promise): Error: No provider for Http!

referred to https://www.youtube.com/watch?v=vuc4dp0qHSc for instructions about integration.

I am new to ionic and am unable to find and debug the issue. Any suggestions are greatly welcomed.

1

1 Answers

0
votes

import HttpModule and add it in app.module.ts page under imports like this,

import { HttpModule } from '@angular/http';

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

remove any other http imports in your app.module.ts page and that should work