I'm wondering how/if it is possible to extend or stack AngularJS directive behavior. What i want to achieve is to define a custom directive as an attribute in a div and be able to cumulatively add elements to the div from multiple calls.
This seems like a similar question to this one: Extending Angular Directive
..which refers to this documentation: https://github.com/angular/angular.js/wiki/Understanding-Directives
the documentation refers to the concept of stacking directives.. but does not have a lot of detail. Below is basically what i am trying but when i add the second directive call it gives an error. Wondering if there is any way to achieve this sort of thing. The motivation is that the main application would have some base content but someone else could come along and extend it without modifying the original code. Is there a better way to achieve this?
error:
Error: Multiple directives [myDirective, myDirective] asking for template on: <div my-directive="">
code:
<div my-directive></div>
myApp.directive('myDirective', function() {
return {
restrict: 'EA',
template : '<div>custom directive 1</div>',
replace : false
};
});
....
myApp.directive('myDirective', function() {
return {
restrict: 'EA',
template : '<div>custom directive 2</div>',
replace : false
};
});