2016-11-28 76 views
0

以下文件分析确定在网上W3C验证:Angular2模板解析器未能在W3C验证HTML片段

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <head> 
    <title>test</title> 
    </head> 
    <body> 
    <ul> 
     <li><div style="margin: 0px 0px 1em; padding: 5px; border: 0px; font-size: 13px; width: auto; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace, sans-serif; display: block; color: rgb(57, 51, 24); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(239, 240, 241);">\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}</div> 
     </li> 
    </ul> 
    </body> 
</html> 

,但下面的代码片段,当作为Angular2模板结合导致的TemplateParser失败:

<main> 
    <ul> 
     <li><div style="margin: 0px 0px 1em; padding: 5px; border: 0px; font-size: 13px; width: auto; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace, sans-serif; display: block; color: rgb(57, 51, 24); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(239, 240, 241);">\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}</div> 
     </li> 
    </ul> 
</main> 

在原始用法中,违规节几乎位于文档片段/模板的末尾。错误输出是:

zone.js:388 Unhandled Promise rejection: Template parse errors: 
Unexpected closing tag "li" (": rgb(239, 240, 241);">\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}</div>[ERROR ->]</li><li><span style="font-size: 13px;"><span style="font-family: Consolas, Menlo, Monaco, &quot;Luci"): [email protected]:10412 
Unexpected closing tag "ul" (": rgb(239, 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li>[ERROR ->]</ul></li></ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0)"): [email protected]:11267 
Unexpected closing tag "li" ("(239, 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li></ul>[ERROR ->]</li></ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0);"><b"): [email protected]:11272 
Unexpected closing tag "ul" (" 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li></ul></li>[ERROR ->]</ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0);"><br/></"): [email protected]:11277 
Unexpected closing tag "div" ("material-icons">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div>[ERROR ->]</div></div></div></main>"): [email protected]:11645 
Unexpected closing tag "div" ("al-icons">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div>[ERROR ->]</div></div></main>"): [email protected]:11651 
Unexpected closing tag "div" ("ns">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div></div>[ERROR ->]</div></main>"): [email protected]:11657 
Unexpected closing tag "main" ("ose</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div></div></div>[ERROR ->]</main>"): [email protected]:11663 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: 
Unexpected closing tag "li" (": rgb(239, 240, 241);">\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}</div>[ERROR ->]</li><li><span style="font-size: 13px;"><span style="font-family: Consolas, Menlo, Monaco, &quot;Luci"): [email protected]:10412 
Unexpected closing tag "ul" (": rgb(239, 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li>[ERROR ->]</ul></li></ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0)"): [email protected]:11267 
Unexpected closing tag "li" ("(239, 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li></ul>[ERROR ->]</li></ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0);"><b"): [email protected]:11272 
Unexpected closing tag "ul" (" 240, 241);"><span style="color: rgb(195, 24, 24);"><br/></span></span></span></span></li></ul></li>[ERROR ->]</ul><div><span style="font-family: monospace, Courier;"><span style="color: rgb(0, 128, 0);"><br/></"): [email protected]:11277 
Unexpected closing tag "div" ("material-icons">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div>[ERROR ->]</div></div></div></main>"): [email protected]:11645 
Unexpected closing tag "div" ("al-icons">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div>[ERROR ->]</div></div></main>"): [email protected]:11651 
Unexpected closing tag "div" ("ns">close</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div></div>[ERROR ->]</div></main>"): [email protected]:11657 
Unexpected closing tag "main" ("ose</i></div><div class="chip">cheatsheet<i class="material-icons">close</i></div></div></div></div>[ERROR ->]</main>"): [email protected]:11663 
    at DirectiveNormalizer.normalizeLoadedTemplate (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:13712:21) 
    at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:13705:53) 
    at ZoneDelegate.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:232:26) 
    at Zone.run (http://localhost:3000/node_modules/zone.js/dist/zone.js:114:43) 
    at http://localhost:3000/node_modules/zone.js/dist/zone.js:502:57 
    at ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:265:35) 
    at Zone.runTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:154:47) 
    at drainMicroTaskQueue (http://localhost:3000/node_modules/zone.js/dist/zone.js:401:35) 
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:339:25)consoleError @ zone.js:388_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339 
zone.js:390 Error: Uncaught (in promise): Error: Template parse errors:(…)consoleError @ zone.js:390_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339 

我在别处看过,由于路由配置不正确,可能会产生类似的错误。我有<base href="/"/>礼物,我是否需要返回并了解有关路由的更多信息?

我发现问题的位置非常接近我所称的特殊字符,它们没有被转义,但W3C解析器甚至声明了一个严格的文档,似乎认为这是确定的。我看到一个不符合标准的解析器吗?

回答

0

问题是,作为Angular 2模板,代码不一定符合HTML,直到所有的替换和处理完成。

https://angular.io/docs/ts/latest/guide/template-syntax.html

在这种情况下,要呈现的乳胶代码包含一个}}序列,其是插值序列的角2的模板端和被解释为这样。人们可以使用{{ '}' }} {{ '}' }}来逃避,但在我的情况下,这种方法导致插值的最大数量被超过。

逐字呈现代码的更好方法是将ngNonBindable指令应用于包含的DOM元素。

https://docs.angularjs.org/api/ng/directive/ngNonBindable