wymsee / cordova-HTTP

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
371 stars 300 forks source link

cordovaHTTP can not be register #155

Open oulinhuao opened 6 years ago

oulinhuao commented 6 years ago

It's a Ionic project. When I register cordovaHTTP in main module ,browser console that:

Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module cordovaHTTP due to:
Error: [$injector:nomod] Module 'cordovaHTTP' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

and my code is:

angular.module('starter', ['ionic','ngCordova', 'cordovaHTTP',
  'starter.DBUtilsService',
  xxxx
 ])

I can't use this plugin. Is there anything wrong with me?

nmckeown commented 6 years ago

Hi There, any fix to this.

I installed this plugin last night and it was working but getting the same problem above now. Not sure why?! Thanks

chr4ss1 commented 6 years ago

the CordovaHTTP.js that exposes angular module gets injected AFTER your app.js has been bootstrapped. You can view the order how files are loaded by injecting yourself in to IOS Webinspector.

In order to fix it, you could try to do manual bootstrapping after the files have loaded. See more info: https://docs.angularjs.org/guide/bootstrap#manual-initialization

nmckeown commented 6 years ago

Hi Chris,

I didn't have much success with the manual bootstrap but what did work for me was just commenting out cordovaHTTP in angular.module. The plugin works fine so all good :-) Thanks for reply

chr4ss1 commented 6 years ago

no problem.

For anyone else struggling & just to let you know-:

the best practice for ionic apps is to bootstrap your application manually. This ensures the dependencies are resolved in the correct order and avoids issues like these.

Here is an example how to manually bootstrap which works for web & phones:

  <script>
    angular.element(document).ready(function () {
      if (window.cordova) {
        document.addEventListener('deviceready', function () {
          angular.bootstrap(document.body, ['ionicApp']);
        }, false);
      } else {
        angular.bootstrap(document.body, ['ionicApp']);
      }
    });
  </script>