EDIT: I realized what I did wrong. I didn’t realize angular http is different from ionic native http and I imported ionic-native http instead of angular http.
Original post:
I’m new to Ionic but I’ve read some of the similar threads on this but still having trouble with it.
Basically what I have is a ionic super template, and I added the HttpModule import to it.
Here’s my app.module.ts,
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { ErrorHandler, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Camera } from '@ionic-native/camera';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { IonicStorageModule, Storage } from '@ionic/storage';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { Items } from '../mocks/providers/items';
import { Settings } from '../providers/providers';
import { User } from '../providers/providers';
import { Api } from '../providers/providers';
import { MyApp } from './app.component';
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
export function provideSettings(storage: Storage) {
return new Settings(storage, {
option1: true,
option2: 'Ionitron J. Framework',
option3: '3',
option4: 'Hello'
});
}
@NgModule({
declarations: [
MyApp
],
imports: [
BrowserModule,
HttpModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
}),
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
],
providers: [
Api,
Items,
User,
Camera,
SplashScreen,
StatusBar,
{ provide: Settings, useFactory: provideSettings, deps: [Storage] },
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule { }
And here’s the other ts file that uses HTTP
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { HTTP } from '@ionic-native/http';
import { Item } from '../../models/item';
import { Items } from '../../providers/providers';
@IonicPage()
@Component({
selector: 'page-search',
templateUrl: 'search.html'
})
export class SearchPage {
currentItems: any = [];
constructor(public navCtrl: NavController, public navParams: NavParams, public items: Items, public storage: Storage, private http: HTTP) { }
}
In the module file I got the import at the top and in imports, no Http in providers. And code in the ts file is basically copy pasted from ionic doc. I don’t know what’s wrong with the code. Please help.