Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordovaHTTP can not be register #155

Open
oulinhuao opened this issue Dec 6, 2017 · 4 comments
Open

cordovaHTTP can not be register #155

oulinhuao opened this issue Dec 6, 2017 · 4 comments

Comments

@oulinhuao
Copy link

oulinhuao commented Dec 6, 2017

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
Copy link

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
Copy link

chr4ss1 commented Apr 10, 2018

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
Copy link

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
Copy link

chr4ss1 commented Apr 10, 2018

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants