ng-repeat parse array to string

advertisements

Is it possible to parse in ng-repeat a array value into a string? I'll explain what I mean.

 <tr ng-repeat="(key,property) in obj.properties">
      <td>{{key}}</td>
      <td>{{property}}</td>
 </tr>

This {{property}} is an array e.g [ 7 , 8 ], but I would like to show "Jully - August". Is it possible through a filter? Or I need to parse it in the controller.


Use filter convert number to name of month:-

<td>{{property|monthName}}</td>

   app.filter('monthName', [function() {
    return function (monthNumber) {
      //1 = January
        var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June',
            'July', 'August', 'September', 'October', 'November', 'December' ];
         var nameList="";
         for(var i=0;i<monthNumber.length;i++){
           if(i==monthNumber.length-1){
         nameList+=monthNames[monthNumber[i] - 1];
           }else{
             nameList+=monthNames[monthNumber[i] - 1]+"-";
           }
         }
         return nameList;
    }
}]);

Plunker