Reputation: 809
Is the ng-repeat of AngularJS 1.x compatible with ES6 Maps?
Upvotes: 5
Views: 1944
Reputation: 51
The easiest way is to create your own angular filter as @Minato suggested.
You can use ES6 Spread syntax to convert map into array:
angular.module('SomeModuleName')
.filter('mapToArray', function() {
return function(map) {
return [...map.values()];
};
});
And then just use it in the template:
<div ng-repeat="item in Map | mapToArray">
You can also use lodash toArray method: https://lodash.com/docs/4.17.4#toArray
Upvotes: 5
Reputation: 7168
See my answer here for a solution to bind ng-repeat
to an ES6 Map
in Angular 1.x.
Upvotes: 0
Reputation: 4533
ngRepeat
currently doesn't support Map
.. to use it either you have to convert it into a JavaScript Array first.. or write a filter to convert it while using it.
see angular-toArrayFilter for reference. You can also create you very own filter like toArraFilter and use it with Map
inside ngRepeat
.
Upvotes: 3