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.

iterate maps with ng-for

See original GitHub issue

I am trying to iterate over Map values with the built in ng-for, but I can see that for some reason it is not working.

In the specs, you can iterate over a Map iterable with:

let map = new Map();
let values = map.values();
for (let item of values) {
    console.log(item);
}

And none of the ES5 standard for (...)/for (... in ...) will work with that.

Does the built in ng-for actually support iterating over maps?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:46 (14 by maintainers)

github_iconTop GitHub Comments

58reactions
mheverycommented, May 31, 2015

Maps have no orders in keys and hence they iteration is unpredictable. This was supported in ng1, but we think it was a mistake and will not be supported in NG2

The plan is to have a mapToIterable pipe

<div *ng-for"var item of map | mapToIterable">

39reactions
MTysoncommented, Nov 22, 2016

“Maps have no orders in keys and hence they iteration is unpredictable”.

So what? Set iteration is unpredicable in Java, does that mean it shouldn’t be iterated over?

No, this is just a mistake made in design that has become obvious in practice.

So much good in angular 2, just fix this thing please.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to iterate using ngFor loop Map containing key as string ...
This is because map.keys() returns an iterator. *ngFor can work with iterators, ...
Read more >
How to iterate using ngFor loop Map containing key as string ...
JavaScript : How to iterate using ngFor loop Map containing key as string and values as map iteration [ Gift : Animated Search...
Read more >
How to iterate over Map using ngFor and display them in order ...
[Solved]-How to iterate over Map using ngFor and display them in order on html in Angular 2+?-angular.js · If the keys are numbers...
Read more >
How to iterate using ngFor loop Map containing ... - SyntaxFix
I am new to angular 5 and trying to iterate the map containing another map in typescript. How to iterate below this kind...
Read more >
How to Iterate/loop map in TypeScript or Angular
Table of Contents · Solution 1 : Use built-in Map forEach function(). · Solution 2: Use ES6 [key,value] syntax · Solution 3: Using...
Read more >

github_iconTop Related Medium Post

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 Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found