如何动态加载控制器?

时间:2014-04-14 08:48:59

标签: angularjs

我已经控制了两个控制器:

<div ng-controller="mainController" ng-init="init({role='widget1'})">   
    <div ng-controller="ctrlToLoad" ng-init="init({action='put'})" ng-include="aVariable">
    </div>

    <div ng-controller="ctrlToLoad" ng-init="init({action='delete'})" ng-include="aVariable">
    </div>
</div>

目的是使用某个控制器动态地将模板加载到第二个div中,具体取决于我的mainController管理的参数,如:

myApp.controller('mainController', function($scope, $sce, ...) {
    if(/*Something*/){
        $scope.ctrlToLoad = 'anOtherController'
    }
});
myApp.controller('anOtherController', function($scope, $sce, ...) {
    // Some jobs...
});

0 个答案:

没有答案