Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ES6 Map with AngularJS ng-repeat

Is the ng-repeat of AngularJS 1.x compatible with ES6 Maps?

like image 972
José María Avatar asked Feb 11 '16 10:02

José María


1 Answers

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

like image 199
Eugene M Avatar answered Sep 28 '22 07:09

Eugene M