Skip to content

Instantly share code, notes, and snippets.

@deanapeterson
Created October 23, 2013 20:51
Show Gist options
  • Save deanapeterson/7126518 to your computer and use it in GitHub Desktop.
Save deanapeterson/7126518 to your computer and use it in GitHub Desktop.
Include a view/template without creation of a new scope. Refined from snippet provided on this stackoverflow entry: http://stackoverflow.com/questions/12393703/how-to-include-one-partials-into-other-without-creating-a-new-scope#answer-17340138. jsFiddle: http://jsfiddle.net/DeanIconWeb/BVXUe/
module.directive('staticInclude', ["$http", "$templateCache", "$compile", "$parse",function($http, $templateCache, $compile, $parse) {
return function(scope, element, attrs) {
var templatePath = $parse(attrs.staticInclude)(scope);
attrs.$observe("staticInclude", function(value){
scope.$watch(value, function(templatePath){
loadTemplate(templatePath);
});
});
function loadTemplate(templatePath){
$http.get(templatePath, {cache: $templateCache}).success(function(response) {
element.html(response);
$compile( element.contents() )(scope);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment