【发布时间】:2018-08-31 04:33:57
【问题描述】:
我正在开发演示项目,如果我不在 P 标签内添加 UL 标签,则可以正常工作。
工作代码:
<p>
<br/> Umesh test help <br/>
</p>
<ul>
<li *ngFor="let user of help2Listdata">
<a routerLink="/details/{{user.hid}}">{{ user.hid }}</a>
<ul>
<li><a href="http://{{ user.name }}">{{ user.name }}</a></li>
<li>{{ user.ans }}</li>
</ul>
</li>
</ul>
非工作代码:
<p>
<br/> Umesh test help <br/>
<ul>
<li *ngFor="let user of help2Listdata">
<a routerLink="/details/{{user.hid}}">{{ user.hid }}</a>
<ul>
<li><a href="http://{{ user.name }}">{{ user.name }}</a></li>
<li>{{ user.ans }}</li>
</ul>
</li>
</ul>
</p>
错误跟踪:
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Unexpected closing tag "p". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags ("
</li>
</ul>
[ERROR ->]</p>"): ng:///Help2Module/Help2Component.html@13:0
Error: Template parse errors:
Unexpected closing tag "p". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags ("
</li>
</ul>
[ERROR ->]</p>"): ng:///Help2Module/Help2Component.html@13:0
at syntaxError (compiler.js:486)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer._preparseLoadedTemplate (compiler.js:3222)
at compiler.js:3202
at Object.then (compiler.js:475)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer._preParseTemplate (compiler.js:3202)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer.normalizeTemplate (compiler.js:3180)
at CompileMetadataResolver.push../node_modules/@angular/compiler/esm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata (compiler.js:14914)
at compiler.js:34420
at Array.forEach (<anonymous>)
at compiler.js:34419
at syntaxError (compiler.js:486)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer._preparseLoadedTemplate (compiler.js:3222)
at compiler.js:3202
at Object.then (compiler.js:475)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer._preParseTemplate (compiler.js:3202)
at DirectiveNormalizer.push../node_modules/@angular/compiler/esm5/compiler.js.DirectiveNormalizer.normalizeTemplate (compiler.js:3180)
at CompileMetadataResolver.push../node_modules/@angular/compiler/esm5/compiler.js.CompileMetadataResolver.loadDirectiveMetadata (compiler.js:14914)
at compiler.js:34420
at Array.forEach (<anonymous>)
at compiler.js:34419
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4751)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
请让我帮助了解为什么会遇到此问题。当我在检查模式下看到工作代码输出时,它似乎很好,但是当更改标签树结构时,它会在浏览器控制台中抛出上述错误。
【问题讨论】:
-
你确定所有打开的标签都关闭了吗?我在非工作代码中看到 p 标签未关闭。
-
stackoverflow.com/questions/4434090/… 不是角度“问题”,只需使用正确的标签