Javascript W3C验证程序在app root的index.html中返回一个错误
我尝试验证我的html页面,但检索到以下错误时:Javascript W3C验证程序在app root的index.html中返回一个错误,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,我尝试验证我的html页面,但检索到以下错误时: Error: Element app-root not allowed as child of element body in this context. (Suppressing further errors from this subtree.) From line 4347, column 7; to line 4347, column 16 r">↩ <app-root> Content model f
Error: Element app-root not allowed as child of element body in this context.
(Suppressing further errors from this subtree.)
From line 4347, column 7; to line 4347, column 16
r">↩ <app-root>
Content model for element div:
Flow content.
Neither tag is omissible.
错误:在此上下文中不允许元素app root作为元素体的子元素。
(正在抑制来自此子树的进一步错误。)
来自第4347行第7列;至第4347行第16列
r“>↩
元素div的内容模型:
流量内容。
两个标签都不可省略。
这是my index.html的html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>
实例
如果可能的话,如何绕过测试?由于Angular可以创建自定义元素以重用组件,app root tag是Angular的自定义元素,用于呈现作为项目根组件的app组件 当转到
src\app\app.component.ts
文件并检查@component
内的选择器
属性时,可以找到此选择器。
应用程序根目录
可以通过更改选择器
属性和标记名更改为您想要的任何名称
HTML验证程序将搜索任何不熟悉的标记并对此进行投诉,即使它是Angular内部使用的自定义元素。
app root
不是HTML标记。app root
不是HTML规范的一部分,因此定义无效。您需要在呈现的HTML输出上运行验证程序如果你必须运行验证器的话,你是说outerHTML吗?因为我试过了,但他没有用。你会想用@加上用户名在评论中回应…我不确定“他”是什么意思“这是不一样的。在任何情况下,您现在都有答案了……您可能希望通知OP这可能是一个带有属性的有效HTML标记,如
,并且他们可以将选择器更改为#app root
。然后验证程序将不会有任何投诉。@HereticMonkey适用于应用程序根目录,但问题仍然存在于在应用程序组件中调用的router outlet指令。