Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.48 KB

File metadata and controls

42 lines (32 loc) · 1.48 KB

HttpModule

Add NativeHttpModuleD and NativeHttpFallbackD into the application's module

import { NgModule } from '@angular/core';
import { NativeHttpFallbackD, NativeHttpModuleD } from 'ionic-native-http-connection-backend';
import { RequestOptions, Http } from '@angular/http';

@NgModule({
    declarations: [],
    imports: [
        NativeHttpModuleD
    ],
    bootstrap: [],
    entryComponents: [],
    providers: [
        {provide: Http, useClass: Http, deps: [NativeHttpFallbackD, RequestOptions]}
    ],
})
export class AppModule {
}

Troubleshooting

I followed installation and usage instructions but still receive CORS issue on app start

Wrap the first request with Platform.ready(). The code will resemble the listing below.

this.platform.ready().then(() => {
  this.http.get('url')
    // subscribe logic goes here
});

ionic-native-http-connection-backend uses cordova-plugin-advanced-http to perform HTTP requests. There is a chance plugin could be initialized in few seconds after app has started. Using ionic-native-http-connection-backend before cordova-plugin-advanced-http has been initialized falls it back to XmlHttpRequest usage.

The above instruction relates to requests performed on app start only. There is no need to wrap all the HTTP requests with Platform.ready.

This is a temporary solution. The issue has been created. Check sneas#14 for it's status.