Created
June 3, 2015 05:34
-
-
Save subtubes-io/b5caa3f12563a87b86a3 to your computer and use it in GitHub Desktop.
Extending AngularJs Directives
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'; | |
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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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]