UPDATE
- First, this is not a bug in Angular (@PSL).
- I've left my original question below for historic purposes.
- This is not a bug in HTML spec. After clicking through on some links from commenters below (@zerflagL), I see that the HTML spec says that VOID ELEMENTS are not synonymous with SELF CLOSING ELEMENTS (here's an SO Q&A on the topic).
- OK, so crappy research on my part.
- Doubling down on this, however:
HTML should include self-closing tags (it appears it no longer does) and siblings should not magically become sub-DOM elements (innerHTML).
Thanks to @PSL, @shaunhusain and @zeroflagL for setting me straight.
I believe I may have found a bug in Angular's custom directive processing and would like confirmation to make sure I haven't misunderstood custom directive behavior. I'm new to AngularJS, so perhaps I've made a mistake.
It looks like when Angular processes a custom directive on a void element, an improper DOM change occurs and peer elements are pushed down to inner HTML. Here's some HTML:
<div ng-app="myApp">
<div ng-app="mainController">
<div>
<voidtagtest></voidtagtest>
<p>Example 1 - stays peer</p>
</div>
<div>
<voidtagtest/>
<p>Example 2 - becomes innerHTML</p>
<p>this one, too.</p>
</div>
</div>
</div>
Here's some JavaScript for Angular:
angular.module('myApp', [])
.controller('mainController', function ($scope) {
$scope.message = 'a msg';
})
.directive('voidtagtest', function () {
return {
restrict: 'E'
};
});
The DOM after Angular processing (requires browser web inspection) is:
...
<div>
<voidtagtest>
<p>Example 2 - becomes innerHTML</p>
<p>this one, too.</p>
</voidtagtest>
</div>
...
Notice how the two Paragraph tags were pulled inside the voidtagtest element?
W3C definition of VOID ELEMENT, if you weren't aware of its syntax.
Here's a jFiddle implementing the entire beast.
Is this a bug or am I missing something? If it is a bug, please recommend how I can file a bug with the Angular team.
Thanks.