Skip to content

Instantly share code, notes, and snippets.

@B-Stefan
Created September 15, 2014 19:52
Show Gist options
  • Save B-Stefan/577f6c638d9abeaff30f to your computer and use it in GitHub Desktop.
Save B-Stefan/577f6c638d9abeaff30f to your computer and use it in GitHub Desktop.
An Angular-Directive to import a template and maintain the Scope
define ['./directives'], (module)->
module.directive 'staticInclude', ($http, $templateCache, $compile)->
(scope, element, attrs)->
templatePath = attrs.staticInclude ? attrs.src;
$http.get(templatePath, { cache: $templateCache }).success (response)->
contents = element.html(response).contents();
$compile(contents)(scope)
@B-Stefan
Copy link
Author

Simple Angular Directive to keep the current scope an alternative for ngInclude

(function() {

  define(['./directives'], function(module) {
    return module.directive('staticInclude', function($http, $templateCache, $compile) {
      return function(scope, element, attrs) {
        var templatePath, _ref;
        templatePath = (_ref = attrs.staticInclude) != null ? _ref : attrs.src;
        return $http.get(templatePath, {
          cache: $templateCache
        }).success(function(response) {
          var contents;
          contents = element.html(response).contents();
          return $compile(contents)(scope);
        });
      };
    });
  });

}).call(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment