2

I'm building Angular 5 application with Angular Universal. Currently I got a problem with W3C validation. The validator is showing errors on every attribute from Angular core.

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.

W3C errors

I read about adding before Angular attributes data- prefix, but on Angular 5 it won't work (I think).

Is there any solution to remove it on server side using Angular Universal, or is there any external tool?

unor
  • 92,415
  • 26
  • 211
  • 360
Patryk Panek
  • 405
  • 4
  • 20
  • https://www.npmjs.com/package/angular-html5 – Martin Schneider Feb 06 '18 at 08:59
  • 1
    You should read a description. I think it won't work with Angular 5. Gr – Patryk Panek Feb 06 '18 at 09:01
  • Is this W3C validation absolutely required? – weirdpanda Feb 06 '18 at 09:06
  • 2
    Related discussion at https://stackoverflow.com/questions/18607437/should-i-care-about-w3c-validation/29023301#29023301. What we need is to get agreement on some standard syntax for custom-attribute names. Some proposals have been discussed at https://github.com/whatwg/html/issues/2271 but there’s been no resolution yet. If/when the HTML spec defines some standard syntax for custom attributes, I could update the W3C HTML checker to recognize them. In the meantime, you can use the message-filtering feature (button) in the checker UI to persistently (using localstorage) filter out those errors – sideshowbarker Feb 06 '18 at 09:32
  • Okey, thank You for answer. I hope it will be avaible soon. – Patryk Panek Feb 06 '18 at 10:31

1 Answers1

0

Angular provide these _ngcontent-c1, _ngcontent-c2 attribute added to specific DOM elements with styles.

_ngcontent-c1 is used unique identity when rendered from server. when we do ViewEncapsulation.Emulated and it's the default behaviour of angular.

If you don't want such kind of attribute so you can add ViewEncapsulation.None or ViewEncapsulation.Native.

eg.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  encapsulation: ViewEncapsulation.None
})
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121