in $scope.reviews = {}; I put an array. Where I need I call something in the spirit:

 <div ng-repeat="review in reviews"> {{review.id}} {{review.name}} {{review.date}} </div> 

How can I do a specific operation with a specific column of this array? For example, format the date. I want to do this not on the side of the template, but in the controller.

Closed due to the fact that the essence of the issue is incomprehensible by the participants of the Grundy , dirkgntly , cheops , user207618, αλεχολυτ 21 Sep '16 at 3:51 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    which means in $ scope.reviews = {}; putting an array ? How can I do a specific operation with a specific column of this array ... not on the template side, but in the controller - I need to cycle through the array and change what I need - Grundy
  • one
    Try using angular.forEach($scope.reviews,function(review){}) . - Stepan Kasyanenko
  • one
    in this case, if you really get an array, this is a regular array and you need to bypass it as usual: for, forEach, etc. - Grundy
  • one
    Because it’s not for nothing that I wrote $scope.reviews in the comments. angular.forEach works with an array. You need to do this: angular.forEach($scope.reviews, function(review) { review.updated_at = review.updated_at.split(" ",3); }); - Stepan Kasyanenko
  • one
    Look better at the @Qwertiy answer. I hope he gives you an example of how to use the filter in the template. - Stepan Kasyanenko

1 answer 1

 var format = $filter("date"); for (var q=0; q<$scope.reviews.length; ++q) { $scope.reviews[q].date = format($scope.reviews[q].date, "yyyy_MM_dd HH:mm:ss"); } 

But in general, it is more logical to use filters from the markup. Starting with version 1.3, the default angular does not perform repeated filter calls.

 <div ng-repeat="review in reviews"> {{review.date | date : "yyyy_MM_dd HH:mm:ss"}} </div> 
  • one
    @ J.Doe, sorry, inattentively read. The answer is updated. - Qwertiy
  • one
    Yes, to display formatted values ​​it is better to use filters in the template. Maybe add an example of using the filter in the template? It is necessary to show how to do better, and not to encourage a person when he moves in the wrong direction)) - Stepan Kasyanenko
  • one
    @StepanKasyanenko, done. - Qwertiy
  • one
    It seems that the questioner in the review.updated_at property review.updated_at not have a Date type, but a String . Therefore, the date filter does not work. This can be seen from his conversion review.updated_at = review.updated_at.split(" ",3); . Maybe show how to create and use a custom filter. - Stepan Kasyanenko
  • one
    @StepanKasyanenko, like date-filter can parse strings, if the format is edible. A custom filter is another question. - Qwertiy