Angular add modules after angular.bootstrap

前端 未结 3 1574
孤独总比滥情好
孤独总比滥情好 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:33

    according to this presentation (slide 12) you can assign controllerProvider to app.

    Example of replacing module's controller method: http://jsfiddle.net/arzo/HB7LU/6659/

    var myApp = angular.module('myApp', []);
    
    //note overriding controller method might be a little controversial :D 
    myApp.config(function allowRegisteringControllersInRuntime($controllerProvider) {
        var backup = myApp.controller;
        myApp.controller = $controllerProvider.register;
        myApp.controller.legacy = backup;
    })
    
    myApp.run(function ($rootScope, $compile) {
    
        myApp.controller('MyCtrl', function($scope) {
            $scope.name = 'Superhero';
        })
    
        var elem;
        var scope=$rootScope;
        elem = $compile('

    {{name}}

    ')($rootScope, function (clonedElement, scope) { console.log('newly created element', clonedElement[0]) document.body.appendChild(clonedElement[0]); }); console.log('You can access original register via', myApp.controller.legacy); })

提交回复
热议问题