I am using the ng-include
directive that will have a dynamic template and controller based on some variables in the scope. Currently I have a map like this.
$scope.map = {
'key1': {
controller: Ctrl1,
templateUrl: 'tmpl1.html'
},
'key12': {
controller: Ctrl2,
templateUrl: 'tmpl1.html'
}
}
...
<div ng-include src="map[key].templateUrl" ng-controller="map[key].controller"></div>
However, I would like to discard this map and instead generate the templateUrl and controller via a string. The following returns the controller object but I need the function to be returned.
var ctrlObj = angular.module('moduleName').controller('ControllerName')
EDIT 1
To clarify:
However, I would like to discard this map and instead generate the templateUrl and controller via a string
Basically I would to set up 'sub-controllers' on a page a way so that it would be convention over configuration. A master controller that has information that all the sub-controllers would share: FooCtrl would be the 'master' controller while FooBarCtrl, FooBarSubCtrl would be sub-controllers. My goal would be to make a function that would resolve "Bar" to "FooBarCtrl" and from that grab the appropriate controller function.