question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML5 data-* not working with template attributes using ngFor

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I ran across this while coding section 3 of the Angular 2 Tutorial, but it seems relevant to the library at large.

The following HTML solutions are currently working in showing a list of items, but they don’t pass the w3c validation:

<li *ngFor="let hero of heroes"> <li template="ngFor let hero of heroes">

When doing the following, though, only one list item is showing:

<li data-template="ngFor let hero of heroes">

Expected/desired behavior

We should have a valid HTML solution available that shows all items, such as one of the following: <li data-template="ngFor let hero of heroes"> <li data-ngTemplate="ngFor let hero of heroes">

Reproduction of the problem

This is re-producible in any *ngFor loop. I’m not sure if similar attributes like *ngIf and others are seeing issues, but it may not hurt to check these as well.

What is the expected behavior?

Any feature should have an attribute that can validate as HTML5 and still work.

What is the motivation / use case for changing the behavior?

The data-* custom attributes allow us to future-proof our pages. The W3C will not add another data-* attribute in the future, so by following this standard, there is no risk of conflicts when a new attribute is added to the specs.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.4
  • Browser: All
  • Language: TypeScript 1.8.10

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
skreborncommented, Jul 8, 2016

@zoechi I think his problem is that neither <li *ngFor="let hero of heroes"> nor <li template="ngFor let hero of heroes"> are valid HTML snippets (according to W3C), so he would like to use data-template instead.

Warning: Attribute *ngfor is not serializable as XML 1.0. Error: Attribute *ngfor not allowed on element li at this point. Error: Attribute template not allowed on element li at this point.

Honestly, I think this just adds complexity, and it’s not the source that should be W3C compliant, but the generated page.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 Template Parse Error on html5 data- attributes
I tried with and without the [] around data-toggle and data-target and neither way seems to work. I've also tried it on the...
Read more >
Repeating Data with ngFor - Pluralsight
*ngFor accepts an array to iterate the data over a HTML template. Begin by creating a local variable for an array consisting of...
Read more >
NgForOf - Angular
A structural directive that renders a template for each item in a collection. ... If a custom TrackByFunction is not provided, NgForOf will...
Read more >
HTML5 Data Attributes in Angular 10/9 - Techiediaries
We can get the value of the data attribute using the dataset property or the getAttribute() method on the messageEl template reference variable....
Read more >
Angular Optimization: Use trackBy Option for *ngFor Directive
So, you see the problem? Because of mutation and Angular CD run, we return a new reference always in our components, and so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found