4

Angular 1.x allowed to put elements in HTML, which were not known for W3C HTML Validator. Workaround for this was to add data- prefix and write e.g. data-ng-repeat instead of ng-repeat.

In the current Angular 2 version we have a different syntax. This syntax is also case-sensitive, e.g. we have to use ngClass, not ngclass.

All brackets used in Angular2 are causing HTML validation errors. Fortunately there is also a canonical form, so instead of (event) we can go with on-event, instead of [property] we can go with bind-property and instead of [(ngModel)] we can use bindon-ngModel. All those things work with data- prefix.

But what with directives like *ngFor, *ngIf and *ngSwitch? What with template variables #variable? Do you know any workaround in order to make Angular 2 template with those things a valid HTML in W3C Validator?

2
  • you want to know how we can define *ngFor and so on by another way ? like on-event ? Commented May 27, 2016 at 10:24
  • I've edited my questions. I would like to use W3C Validator with my Angular 2 templates. Is the ignoring things like *ngFor the only way? Commented May 27, 2016 at 10:33

1 Answer 1

3

You have to use the canonical form. The * is for structural directives which can be used with the <template> tag. With * the template is implicit, but you can always use an explicit template tag instead and with this the canonical forms of the bindings you listed above.

See * and <template> in https://angular.io/docs/ts/latest/guide/template-syntax.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I was looking for something like this! Full chapter name is "* and <template>", you have just "* and ".
Sorry, was a formatting issue. SO swallowed the rest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.