Skip to content

Instantly share code, notes, and snippets.

@olostan
Created December 27, 2012 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save olostan/4387706 to your computer and use it in GitHub Desktop.
Save olostan/4387706 to your computer and use it in GitHub Desktop.
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