Разобрался вроде...
пример: //тут могут быть ошибки так как я упростил код. Но примерно выглядит так
Angular:
var phonecatApp = angular.module('myyApp', []);
phonecatApp.config(function($controllerProvider, $compileProvider, $filterProvider, $provide) {
phonecatApp.register = {
controller: $controllerProvider.register,
directive: $compileProvider.directive,
filter: $filterProvider.register,
factory: $provide.factory,
service: $provide.service
};
});
function reg (obj,text) {
phonecatApp.register.controller(obj, function ($scope) {
$scope.text = text;
)};
};
phonecatApp.directive('myDir',['$http','$compile', function($http,$compile) {
return function(scope, element){
$http.get('file.json').success(function(data) {
//registration of controllers
regCtrl(data[1].objName,data[1].text);
regCtrl(data[2].objName,data[2].text);
//getting template
var tpl = data[0].tpl;
//create an angular element. (this is our "view")
var el = angular.element(tpl);
//compile the view into a function.
var compiled = $compile(el);
//append our view to the element of the directive.
element.append(el);
//bind our view to the scope!
compiled(scope);
});
}
}]);
json:
[
{"tpl":"<div ng-controller='italic'><i>{{text}}</i></div><div ng-controller='bold'><b>{{text}}</b></div>"
},
{
"objName": "italic",
"text": "Этот текст написан курсивом"
},
{
"objName": "bold",
"text": "Этот текст жирный"
}
]
HTML:
<body ng-app="myyApp">
<div my-dir></div>
</body>