Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
zsong opened this Issue · 4 comments

3 participants

@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

@CalvinFernandez

This error is thrown because there is no module 'myApp'. You must create a module using angular.module('myApp', []) if you intend to use it anywhere.

angular.bootstrap does not create modules; It compiles and links the DOM against any modules that you've passed in.

@jamesdaily

@CalvinFernandez I think the idea is that the creation can be done on the fly by bootstrap.

angular.module can either reference an existing module (by passing just a module name), or create a new module (by passing a module name as well as a definition).

Since angular.bootstrap takes in an array of module declarations as a parameter, it should support not only module declarations which reference existing modules, but also support module declarations which create new modules.

If angular.bootstrap is meant to only accept references to existing modules, and is not meant to support creating new modules inline, then its parameter definition ought to be modified and the documentation changed.

@CalvinFernandez

@jamesdaily ah, I see the confusion. I'm curious, how would you change the bootstrap parameter definition?

@CalvinFernandez

#3733 Proposed change to docs

@petebacondarwin petebacondarwin closed this issue from a commit
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
327a786
@petebacondarwin petebacondarwin referenced this issue from a commit
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
e3371d7
@blesh blesh referenced this issue from a commit
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
e1b2007
@jamesdaily jamesdaily referenced this issue from a commit in jamesdaily/angular.js
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
8bf1797
@jamesdaily jamesdaily referenced this issue from a commit in jamesdaily/angular.js
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
10d867d
@jesselpalmer jesselpalmer referenced this issue from a commit
@petebacondarwin petebacondarwin docs(angular.bootstrap): clarify modules parameter
It was not clear what you could pass to specify modules to load in the
`module` parameter of this function. The `modules` parameter takes an
array.

The main case is to provide a String, which is the name of a "predefined"
angular module.
The side cases are to provide a Function (or an annotated function in the
form of an Array), which will be invoked by the injector as a run block.

It is not possible to "define" new modules via this parameter.

Closes #3692
8e417a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.