Skip to content

Instantly share code, notes, and snippets.

@carmichaelize
Created November 8, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmichaelize/364bb3c4f5b6958b9f3b to your computer and use it in GitHub Desktop.
Save carmichaelize/364bb3c4f5b6958b9f3b to your computer and use it in GitHub Desktop.
Custom Angular directive transclusion functions
//Shared scope
function myDirective() {
return {
restrict: 'EA',
templateUrl: 'my-directive.html',
transclude: true,
scope: false,
controllerAs: 'ctrl',
link: function(scope, element, attrs, ctrl, transclude) {
transclude(scope, function(clone, scope) {
element.find('.transclude-placeholder').append(clone);
});
}
};
}
//Isolated scope
function myDirective() {
return {
restrict: 'EA',
templateUrl: 'my-directive.html',
transclude: true,
scope: {},
controllerAs: 'ctrl',
controller: function(){
var ctrl = this;
},
link: function(scope, element, attrs, ctrl, transclude) {
transclude(scope.$parent, function(clone, scope) {
element.find('.transclude-placeholder').append(clone);
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment