2

Why can I not use empty element tags in my ng2 template. It is the same with the section as with a file in templateUrl.

<p></p>    // OK

<p/>       // NOK (endless "Loading...")

???

cheers, chris

kind user
  • 32,209
  • 6
  • 49
  • 63
chris01
  • 8,111
  • 7
  • 35
  • 65

2 Answers2

3

p tag is not a non closing element in html. The non-closing elements are e.g. img, input or br. If you don't close it - the loading will be shown endlessly because the compiler will throw a template parse error:

Uncaught Error: Template parse errors:
Only void and foreign elements can be self closed "p" ("
</p>
[ERROR ->]<p/>
kind user
  • 32,209
  • 6
  • 49
  • 63
1

Angular2 only allows valid HTML5 in component templates.

See also https://stackoverflow.com/a/3558200/217408

  • In HTML5, the meaning of <foo /> [depends on the type of element][1].

    • On HTML elements that are designated as void elements, end tags are simply forbidden. The slash at the end of the start tag is allowed, but has no meaning. It is just syntactic sugar for people (and syntax highlighters) that are addicted to XML.
    • On other HTML elements, the slash is an error, but error recovery will cause browsers to ignore it and treat the tag as a regular start tag. This will usually end up with a missing end tag causing subsequent elements to be children instead of siblings.

    • Foreign elements (imported from XML applications such as SVG) treat it as self-closing syntax.

    [1]: https://www.w3.org/TR/html5/syntax.html#start-tags

Community
  • 1
  • 1
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404