I did this:
var Component = (function() {
function Component(element, attrs, modules, scope) {
var self = this;
this.scope = scope;
this.element = null;
if (!element) {
return;
}
element = $j(element);
modules.unshift(['$provide', function($provide) {
$provide.value('$rootElement', element);
}]);
modules.unshift('ng');
angular.injector(modules).invoke(function($rootScope, $compile) {
if (!scope) {
self.scope = $rootScope.$new();
}
for (var k in attrs) {
element.attr(k, attrs[k]);
}
self.element = $compile(element[0].outerHTML)(self.scope);
$j(element).replaceWith(self.element);
$rootScope.$apply();
});
}
Component.prototype.destroy = function() {
this.scope.$destroy();
};
return Component;
})();
var atts = {
'my-directive': ''
};
return new Component(element, atts, ['myApp']);
I can basically give it a dom element, and some attributes to attach (add your directive or controller atts here).
I think it is probably assuming that an angular app is existing on the page already (i have an angular app bootstrapped a dome element in a different part of the page. Otherwise you might need to roll it up.
Im not sure how you mean 'routing'. I'd have an angular app bootstrapped in to the page, which manages the routing and generates all of these components where needed (in their own elements)
There might be a better way - this is just my hack to play with the idea of components