angularjs - How to dynamically load a controller? -
i've 2 controller ensted:
<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>
the aim dynamically load template second div controller, depending of parameters managed maincontroller like:
myapp.controller('maincontroller', function($scope, $sce, ...) { if(/*something*/){ $scope.ctrltoload = 'anothercontroller' } }); myapp.controller('anothercontroller', function($scope, $sce, ...) { // jobs... });
Comments
Post a Comment