Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS : File concatenation breaks module declaration order
    primarykey
    data
    text
    <p>I'm using grunt to concatenate my <code>.js</code> files for my Angular app.</p> <p>I've just gone through and tidied up the codebase to follow the conventions discussed <a href="https://github.com/yeoman/generator-angular/issues/109" rel="nofollow noreferrer">here</a>, specifically, grouping my code into small modules that represent features.</p> <p>However, I'm finding that the order of concatenation appears to break the app, if a module is consumed before it is declared.</p> <p>eg:</p> <pre><code>|-- src/ | |-- app/ | | |-- userProfile/ | | | | userProfile.js | | | |-- deposits/ | | | | |-- depositFormCtrl.js </code></pre> <p>Where:</p> <pre><code>// userProfile.js var userProfile = angular.module('userProfile',[]) // depositFormCtrl.js angular.module('userProfile') .controller('DepositFormCtrl', function($scope) {...}); </code></pre> <p>When grunt performs the concatenation, <code>depositFormCtrl.js</code> appears before <code>userProfile.js</code>. This causes the app to throw an error, complaining:</p> <blockquote> <p>Uncaught Error: No module: userProfile</p> </blockquote> <p>I see lots of talk about the possibilities of using RequireJS / AMD to manage the load order of the modules. However, often it's stated that this is overkill / not required, <a href="https://stackoverflow.com/a/16113733/59015">as Angular handles this for you</a>.</p> <p>E.g: Brian Ford of the Angular team <a href="https://groups.google.com/d/msg/angular/na9w48QISr4/0jO1b39IYnwJ" rel="nofollow noreferrer">mentioned</a>:</p> <blockquote> <p>My personal take is that RequireJS does too much; the only feature that AngularJS's DI system is really missing is the async loading. </p> </blockquote> <p>He's also stated <a href="http://briantford.com/blog/huuuuuge-angular-apps.html" rel="nofollow noreferrer">elsewhere</a> that he doesn't recommend RequireJS with Angular.</p> <p>I've also seen mentioned made to using <a href="http://code.angularjs.org/1.1.5/angular-loader.js" rel="nofollow noreferrer">angular-loader.js</a>, as shown on the <a href="https://github.com/angular/angular-seed/blob/master/app/index-async.html" rel="nofollow noreferrer">seed project</a>. However, as I understand it, (there's little official documentation) the loader aims to solve the problem of loading modules out of order, rather than them being referenced before used.</p> <p>Adding angular-loader.js to my project didn't resolve the issue.</p> <p>Is there a declaration I should be using that prevents the errors I'm having?</p> <p>What is the correct way to declare modules &amp; controllers, so that the order files are concatenated doesn't impact the code at runtime?</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.
 

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