Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module('myApp.directives',[])
.directive('rawInclude', [
'$http', '$templateCache', '$compile',
function ($http, $templateCache, $compile) {
return {
restrict: 'ECA',
terminal: true,
scope: false,
compile: function (telement, attr) {
var srcExp = attr.rawInclude || attr.src;
return function (scope, element) {
var changeCounter = 0;
scope.$watch(srcExp, function (src) {
var thisChangeId = ++changeCounter;
if (src) {
$http.get(src, { cache: $templateCache }).success(function (response) {
if (thisChangeId !== changeCounter) return;
element.html(response);
$compile(element.contents())(scope);
}).error(function () {
if (thisChangeId === changeCounter) element.html('');
});
}
else element.html('');
});
};
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.