var app = angular.module('myApp', );
.. ran it and BOOM! Got this:
To make it more interesting replacing:
Worked just fine. It obviously didn't have anything to do with display of the element as div s well as p are both block, yet div works fine, p didn't.
Then I started debugging and after a while I realised what a dummy I've been. Given original code, the browser was interpreting it as:
This excerpt from specs should clarify what the issue was:
A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, div, dl, fieldset, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, nav,ol, p, pre, section, table, or ul, element, or if there is no more content in the parent element and the parent element is not an a element.
If you ever read the HTML specs you already know that some elements do not need to have closing end tags. I was well aware of this yet at this point didn't realised that was the issue.
Decided to dig further into AngularJs source itself to see what exactly is going on in there and as it turned out innerHTML is the culprit:
AngularJs nicely passes template code to JQLite (highlighted in yellow below) and JQLite at some point runs it via innerHTML. This spits out modified as per above specs code. Then as shown below, AngularJs checks if the code is valid, so have one root only:
One root meaning:
As the code JQLite spits out is:
It fails the check and Angular throws Error.
All this Googling and head scratching could be avoided if I only remembered the basic specs. Shame on me.. =/