I want to use my directives within other directives. The following example gives so strange results that I had to give up and ask this question. I would like someone to explain me what is going on here:
var app = angular.module('blah', []);
app.directive('one', function() {
return {
restrict: 'E',
replace: true,
template: '<outer>one</outer>'
};
});
app.directive('two', function() {
return {
restrict: 'E',
replace: true,
template: '<outer>two</outer>'
};
});
app.directive('outer', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
template: '<div ng-transclude></div>'
};
});
HTML:
<outer>whatever</outer>
<one></one>
<two></two>
<outer>something</outer>
The resulting DOM is:
<div ng-transclude=""></div>
<outer></outer>
<two></two>
<outer>something</outer>
JSFiddle: http://jsfiddle.net/WPpUL/
Is it a bug?
EDIT:
Expected output DOM:
<div ng-transclude>whatever</div>
<div ng-transclude>one</div>
<div ng-transclude>two</div>
<div ng-transclude>something</div>
replace: falsealso resolves this. For some reason under the combination you have angular thinks two directives are competing to apply templates and thus your error. It appears you're not the only one puzzled by this. The last question here is very similar to yours: docs.angularjs.org/error/…