JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app='app' ng-controller='OuterCtrl'>
<div ng-dynamic-controller='dynamicCtrl'>
{{message}}
</div>
</div>
JavaScript
angular.module('app', [])
.directive("ngDynamicController",function($compile){
return {
terminal: true,
priority: 1000,
link:function(scope,element,attr){
var controllerProperty = scope[attr.ngDynamicController];
element.attr('ng-controller', controllerProperty);
element.removeAttr("ng-dynamic-controller");
$compile(element)(scope);
}
}
})
.controller('OuterCtrl', ['$scope',
function(scope) {
scope.dynamicCtrl = 'InnerCtrlFromModule';
}
])
.controller('InnerCtrlFromModule',['$scope', function($scope) {
$scope.message = 'from controller defined in module - want';
}])