Skip to content

Instantly share code, notes, and snippets.

@VanDalkvist
Forked from raghava/ngIncludeView.js
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save VanDalkvist/57a3612473f171a532c5 to your computer and use it in GitHub Desktop.

Select an option

Save VanDalkvist/57a3612473f171a532c5 to your computer and use it in GitHub Desktop.
// ng-include-view
// - directive in module ng
//
// This works similar to ng-include and it won't create new scope,
// instead it uses the same level
//
// Example usage:
// <ng-include-view src=""></ng-include-view>
'use strict';
angular
.module('App', [])
.directive('ngIncludeView', function($compile, $templateCache) {
return {
restrict: "EA",
link: function($scope, elem, attrs){
var templateUrl = attrs.src;
$scope.$watch(templateUrl, function(){
elem.html($templateCache.get(arguments[0]));
$compile(elem.contents())($scope);
}, true);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment