// usage: evoapp.directive('partialsRenderer', function($rootScope, $compile) { return { restrict: 'AE', link: function (scope, elem, attrs) { scope.partialId = attrs.partialId || null; if(scope.partialId != null){ var partialEL = $rootScope.viewCache.find('[id=' + scope.partialId + ']'); if(partialEL.length == 0){ throw Error('partial ' + scope.partialId + ' not found!'); }else{ if(partialEL.length > 1){ throw Error('more than one partial ' + scope.partialId + ' was found!'); }else{ var finalEl = $.parseHTML(partialEL.html()); $(finalEl).insertAfter(elem); elem.remove(); $compile(finalEl)(scope); } } } } } });