在p标记内添加ul时,角度模板解析错误

问题描述 投票:-1回答:1

我正在开发演示项目,如果我没有在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)

请让我帮忙了解为什么我会面临这个问题。当我在检查模式下看到工作代码输出时似乎很好但是当更改标签树结构时,它会在浏览器控制台中抛出错误。

html angular2-template
1个回答
0
投票

实际上根据w3c规范,p标签内不允许使用ul标签。这将失败。尝试使用div或ng-content等其他标记。

编辑:根据W3C spec,p标签只能包含“Phrasing elements”,这只能在以下标签中:

a
em
strong
small
i
b 

See full list...

© www.soinside.com 2019 - 2024. All rights reserved.