Skip to content

Instantly share code, notes, and snippets.

@subtubes-io
Created June 3, 2015 05:34
Show Gist options
  • Save subtubes-io/b5caa3f12563a87b86a3 to your computer and use it in GitHub Desktop.
Save subtubes-io/b5caa3f12563a87b86a3 to your computer and use it in GitHub Desktop.
Extending AngularJs Directives
'use strict';
angular.module('extndApp')
.directive('parent', function () {
return {
template: '<div>' +
'<ul>' +
'<li>Hello</li>' +
'<li>World</li>' +
'<li>Foo</li>' +
'<li>Bar</li>' +
'</ul>' +
'</div>',
restrict: 'E',
link: function postLink() {
console.log('this is the parent function');
}
};
});
angular.module('extndApp')
.directive('child', function (parentDirective) {
var child = angular.extend({}, parentDirective[0]);
child.template = '<div>This is the child element</div>';
return child;
});
@subtubes-io
Copy link
Author

The only thing is you cannot seem to overwrite the link function. And the syntax for accessing the directive object literal is funky parentDirective[0]

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