Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is in the flow of execution of Angular's code. To integrate on @pkozlowski.opensource's answer and related comments, note that the <code>$injector</code> property is made available to DOM elements after the module code is executed, so that when you access the property (as when you try to <code>console.log</code> it) the property will still be <code>undefined</code>.</p> <p>You can solve this problem by simply setting a 0 timeout to the execution of the logging function (i.e., no explicit delay in milliseconds is needed). This hack works because the logging function will be executed when the stack is empty, that is when Angular's bootstrapping has finished and the <code>$injector</code> property is available to the DOM elements.</p> <p>Another (maybe better) solution in Angular's lingo would be to include your <code>$injector</code>-accessing code in a <a href="http://docs.angularjs.org/guide/module" rel="nofollow">run block</a> (see also the <a href="http://docs.angularjs.org/api/angular.Module" rel="nofollow">related API</a>). The <code>$injector</code> could then be easily injected into the initialization function as a normal service. This works because run blocks are queued and executed asynchronously when all bootstrapping has terminated.</p> <p>Below you can find two fiddles, one for each solution.</p> <p><a href="http://jsfiddle.net/tetotechy/YHdH4/3/" rel="nofollow">0 Timeout jsFiddle</a></p> <p><a href="http://jsfiddle.net/tetotechy/kP4Bs/1/" rel="nofollow">Run block jsFiddle</a></p> <h2>EDIT</h2> <p>Also, there is usually no need to explicitly load the <code>ng</code> module. In normal cases, the <code>ng</code> model is already automatically loaded, unless you want to perform a manual bootstrap of Angular's code. The piece of docs referenced in one of the answers refers (implicitly, unfortunately) to Angular's manual bootstrapping procedure, when you have to manually create the injector and tell it which modules you want to load</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload