Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular.bootstrap(document, ['myApp']); throws error "Uncaught Error: No module: myApp " #3692

Closed
@zsong

Description

@zsong

It seems a bug (Angular 1.1.5), long story short...

In the documentation, it says "When passed two or more arguments, a new module is created. If passed only one argument, an existing module (the name passed as the first argument to module) is retrieved." And this is the example code

  <!doctype html>
  <html xmlns:ng="http://angularjs.org">
    <body>
      Hello {{'World'}}!
      <script src="http://code.angularjs.org/angular.js"></script>
      <script>
         angular.element(document).ready(function() {
           angular.bootstrap(document, ['optionalModuleName']);
         });
      </script>
    </body>
  </html>

But this code doesn't work any more since it can't create the module any more.

The bootstrap function calls createInjector with the module list ['ng', ['ngLocale', function(){...}] , 'myApp'] (the last one is the module you passed in)

function bootstrap(element, modules) {
    ...
    var injector = createInjector(modules);

Inside createInjector(), it calls loadModules for each module passed in

function createInjector(modulesToLoad) {
    forEach(loadModules(modulesToLoad), function(fn) { instanceInjector.invoke(fn || noop); });

And loadModules calls angularModule, which is initialized as angularModule = setupModuleLoader(window);, which creates the object window.angular.module

function loadModules(modulesToLoad){
    ....
    var moduleFn = angularModule(module); // triggers the error

The the error occurs, since angularModule takes 2nd parameter as requires. Without it, it will throws an exception on this line (line 1148) throw Error('No module: ' + name);

So I guess I can report it and they will fix it shortly hopefully.

JSFiddle: http://jsfiddle.net/puEAx/
Stackoverflow: http://stackoverflow.com/questions/16545204/manually-bootstrapping-angularjs-and-then-getting-the-module

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions