简体   繁体   English

Angular 5 - W3C 标记验证

[英]Angular 5 - W3C markup validation

I'm building Angular 5 application with Angular Universal.我正在使用 Angular Universal 构建 Angular 5 应用程序。 Currently I got a problem with W3C validation.目前我遇到了 W3C 验证问题。 The validator is showing errors on every attribute from Angular core.验证器显示来自 Angular 核心的每个属性的错误。

For example, for code part like:例如,对于代码部分,如:

<span _ngcontent-c1="" class="sr-only">Toggle</span>

I'm getting error like:我收到如下错误:

Attribute _ngcontent-c1 not allowed on element span at this point.属性_ngcontent-c1不允许在元素span上。

W3C 错误

I read about adding before Angular attributes data- prefix, but on Angular 5 it won't work (I think).我阅读了在 Angular 属性data-前缀之前添加的内容,但在 Angular 5 上它不起作用(我认为)。

Is there any solution to remove it on server side using Angular Universal, or is there any external tool?是否有任何解决方案可以使用 Angular Universal 在服务器端删除它,或者是否有任何外部工具?

Angular provide these _ngcontent-c1 , _ngcontent-c2 attribute added to specific DOM elements with styles. Angular 提供这些_ngcontent-c1_ngcontent-c2属性添加到具有样式的特定 DOM 元素。

_ngcontent-c1 is used unique identity when rendered from server.从服务器渲染时, _ngcontent-c1用作唯一标识。 when we do ViewEncapsulation.Emulated and it's the default behaviour of angular.当我们执行ViewEncapsulation.Emulated ,它是 angular 的默认行为。

If you don't want such kind of attribute so you can add ViewEncapsulation.None or ViewEncapsulation.Native .如果您不想要这种属性,则可以添加ViewEncapsulation.NoneViewEncapsulation.Native

eg.例如。

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  encapsulation: ViewEncapsulation.None
})

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

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