Hello,
I wanna use the ionic native with cordova-plugin-advanced-http for making requests.
But this combination only works on device ios or android. Is it possible to consider a fallback when the request is made by the desktop browser… ?
Hello,
I wanna use the ionic native with cordova-plugin-advanced-http for making requests.
But this combination only works on device ios or android. Is it possible to consider a fallback when the request is made by the desktop browser… ?
ok I wrote my own provider depending on the platform as same as here
but I got an error
compiler.es5.js:1694 Uncaught Error: Can't resolve all parameters for dynamicHttpProvider: ([object Object], ?, ?).
I think I make a mistake in app.module.
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {CookieService} from 'angular2-cookie/core';
import {IonicApp, IonicModule} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {HttpModule, Http} from '@angular/http';
import {TranslateModule, TranslateLoader, TranslateService} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {IonicStorageModule} from '@ionic/storage';
import { HTTP } from '@ionic-native/http';
import {Platform} from 'ionic-angular';
import {MyApps} from './app.component';
import {HomePage} from '../pages/home/home';
import {HttpAngularProvider} from '../utils/providers/http-angular';
import {HttpNativeProvider} from '../utils/providers/http-native';
import {HttpProvider} from '../utils/providers/provider';
import {RequestService} from '../utils/RequestService';
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
export function cookieServiceFactory() {
return new CookieService();
}
export function dynamicHttpProvider(platform: Platform, httpAngularProvider: HttpAngularProvider, httpNativeProvider: HttpNativeProvider) {
return new HttpProvider(platform, httpAngularProvider, httpNativeProvider);
}
@NgModule({
declarations: [
MyApps,
HomePage
],
imports: [
HttpModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient]
}
}),
BrowserModule,
IonicModule.forRoot(MyApps),
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApps,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: CookieService, useFactory: cookieServiceFactory},
{provide: HttpProvider, useFactory: dynamicHttpProvider, deps: [
Platform,
HttpAngularProvider,
HttpNativeProvider
]},
HTTP,
RequestService
]
})
export class AppModule {
}
The usage in RequestService.ts
@Injectable()
export class RequestService{
constructor(
private httpProvider: HttpProvider) {
// httpProvider.http.post....
}