Created
March 31, 2015 19:36
-
-
Save mewdriller/5768d2524bd7983cea4c to your computer and use it in GitHub Desktop.
An AngularJS directive to transclude while using the contextual scope.
This file contains 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
'use strict'; | |
module.exports = /*@ngInject*/ function scopedTransclude() { | |
return { | |
link: function postLink(scope, iElement, iAttributes, controller, transclude) { | |
if (!transclude) { | |
throw minErr('ngTransclude')('orphan', | |
'Illegal use of ngTransclude directive in the template! ' + | |
'No parent directive that requires a transclusion found. ' + | |
'Element: {0}', | |
startingTag($element)); | |
} | |
var innerScope = scope.$new(); | |
transclude(innerScope, function (clone) { | |
iElement.empty(); | |
iElement.append(clone); | |
iElement.on('$destroy', function () { | |
innerScope.$destroy(); | |
}); | |
}); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment