Angular add modules after angular.bootstrap

前端 未结 3 1585
孤独总比滥情好
孤独总比滥情好 2021-02-04 02:41

I\'m using meteor + angular. My intention is to add more dependencies after the app bootstrap (This is because the package is the one handling the bootstrapping at the start and

3条回答
  •  面向向阳花
    2021-02-04 03:07

    The only method that I've seen that works is replacing the angular.module function with your own function returning the module you used to bootstrap your app.

    var myApp = angular.module('myApp', []);    
    angular.module = function() {
        return myApp;
    }
    

    So that all modules that are registered afterwards are actually being registered in your myApp module.

    This method combined with the one you describe in the question (using providers like $controllerProvider) will allow you to add "modules" after angular.bootstrap.

    Demo

    See this jsfiddle for a demo: https://jsfiddle.net/josketres/aw3L38r4/

    Drawbacks

    • The config blocks of the modules that are added after angular.bootstrap will not be called. Maybe there's a way to fix this, but I haven't found it.
    • Overriding angular.module feels like a "dirty hack".

提交回复
热议问题