Created
February 28, 2014 15:16
-
-
Save guillaume86/9272837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $compileCache = function ($http, $templateCache, $compile) { | |
var cache = {}; | |
return function (src, scope, cloneAttachFn) { | |
var compileFn = cache[src]; | |
if (compileFn) { | |
compileFn(scope, cloneAttachFn); | |
} else { | |
$http.get(src, { cache: $templateCache }).success(function (response) { | |
var responseContents = angular.element('<div></div>').html(response).contents(); | |
compileFn = cache[src] = $compile(responseContents); | |
compileFn(scope, cloneAttachFn); | |
}); | |
} | |
}; | |
}; | |
var ngIncludeCached = function ($compileCache) { | |
return { | |
restrict: 'ECA', | |
terminal: true, | |
compile: function (element, attr) { | |
var srcExp = attr.ngIncludeCached || attr.src; | |
return function (scope, element) { | |
var src = scope.$eval(srcExp); | |
var newScope = scope.$new(); | |
$compileCache(src, newScope, function (compiledElm, newScope) { | |
element.append(compiledElm); | |
}); | |
}; | |
} | |
}; | |
}; | |
angular.module("app") | |
.factory("$compileCache", ['$http', '$templateCache', '$compile', $compileCache]) | |
.directive("ngIncludeCached", ['$compileCache', ngIncludeCached]); |
Very late I know: It was just a copy of ngInclude with some changes, must comes from there.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you use the 'terminal' attribute on the directive?
AFAIK terminal: true would have no affect without priority.