0

I'm looking at managing my AngularJS code using RequireJS and have come up with the following pattern:

"use strict";

(function () {

    var moduleName = "module.name";

    define(
        [
            'angular'
        ],
        function (
            ng
        ) {

            ng.module(moduleName, []);

            return moduleName;

        }
    );

})();

I guess the general idea is that whenever my module/controller/etc... is included, rather than returning the object itself, it binds it's name into Angular and then returns that handle to the caller.

One question I have - Would it be a better idea to return the array parameter I'm passing to ng.module and then eliminate the call, allowing the "includer" of this module to decide what name to bind to?

Are there any other pitfalls or recommendations for designing nicely encapsulated AngularJS+RequireJS modules that could be applied to this pattern? Anything I should watch out for to avoid hardship or confusion in the future?

2
  • Have tried your code to see if it is working after angular.bootstrap? I am pretty sure that modules created using your pattern after bootstrap cannot be injected into your app. Take a look at my question here stackoverflow.com/questions/19134023/… Commented Apr 2, 2014 at 6:53
  • 1
    Actually that same pattern is the one I use to create AngularJS apps. Checkout the example code at my Github: github.com/leog/epsilon Commented Sep 1, 2014 at 1:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.