VanDalkvist
2/5/2015 - 1:24 PM

ngIncludeView.js

// 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);
      }
    };
  });