Created
November 8, 2015 13:45
-
-
Save carmichaelize/364bb3c4f5b6958b9f3b to your computer and use it in GitHub Desktop.
Custom Angular directive transclusion functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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