简体   繁体   English

模板解析错误:意外的结束标记“ p”

[英]Template parse errors: Unexpected closing tag “p”

I want to format XML file in Angular. 我想在Angular中格式化XML文件。 I tried this: 我尝试了这个:

<div class="element-box">
  <div class="details-wrapper">
    <p><b class="label">Raw Request</b>
      <pre>
        {{apiattempt.raw_request | xmlBeautyfier }}
      </pre>
    </p>
  </div>
</div>

But I get this error: 但是我得到这个错误:

ERROR in : 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 ("
        {{apiattempt.raw_request | xmlBeautyfier }}
      </pre>
    [ERROR ->]</p>
    <p><b class="label">Raw Response</b>{{apiattempt.raw_response | xmlBeautyfier }}</p>
  </div"): 

Do you know how I can fix this? 你知道我该怎么解决吗?

The <pre> tag is a block level element. <pre>标签是一个块级元素。 When that is placed inside the <p>...</p> it will act like a </p> causing it to close and throwing an error when it gets to your </p> . 当被置于其内的<p>...</p>它会像一个</p>使其闭合,当它得到抛出一个错误,你的</p> Either close the <p> before your <pre> or wrap the pre in a different element if you want it wrapped. <pre> <p>之前关闭<p> ,或者如果希望将pre包装,则将其包装在其他元素中。

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p

From html.com : 来自html.com

The closing <p> tag is optional and is implied by the opening tag of the next HTML element encountered in an HTML document after an opening <p> tag. 结束<p>标记是可选的,并且隐含在开始<p>标记之后HTML文档中遇到的下一个HTML元素的开始标记。

Refer to: https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags 请参阅: https : //www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags

In HTML: p tag is implicity closed with next element. 在HTML中:p标记被next元素隐式关闭。 So 所以

  • the first p tag starts p and ends with b or pre tag. 第一个p标签以p开头,以b或pre标签结束。 (it is implicitly closed). (它是隐式关闭的)。
  • then then the parser finds /p closing tag for which it doesnt see the preceding p tag. 然后,解析器将找到/ p结束标记,而该标记没有看到前面的p标记。 (the first one was implicitly closed). (第一个隐式关闭)。

Solutions (from best the worst): 解决方案(从最好到最坏):

  • dont use p when you do more tricky stuff. 当您做更多棘手的事情时,请不要使用p。 You have pre tag so you should consider changing your original p with div or span 您具有pre标签,因此您应考虑使用div或span更改原始p
  • OR drop /p (ok idea) 或放/ p(好主意)
  • OR add p in the front of /p. 或者在/ p前面添加p。 (bad idea to have there /p ..) (有/ p ..的好主意。)

Possible solution to investigate: - XHTML requires explicit closing p tag. 研究的可能解决方案:-XHTML需要显式关闭p标签。 You can try to use XHTML and let us know if it works. 您可以尝试使用XHTML,并让我们知道它是否有效。 Note: this is a bit of an overkill to your problem... bit always good to learn ;-) 注意:这对于您的问题来说有点过大了……学习总是很不错的;-)

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM