prozaek.prozaek prozaek.prozaek - 1 year ago 65
AngularJS Question

Why does not the filter?

Please help fix the script.


<li ng-repeat="date in dateArr | dateFormatter}">
<span class="date">{{date}}</span>


angular.module('App', [])
.controller('lsController', function ($scope) {
$scope.dateArr = [

/*$scope.dateFormatter = function(date) {
return date.slice(0, 6);
.filter('dateFormatter', function (date) {
return date.slice(0, 6);

I use angular 1.4.8


I need use filter, which cut the datestring

Answer Source

Your filter is not constructed properly.

A filter needs to return a function that contains the arguments for the filtering and returns the result

.filter('dateFormatter', function () {
      return function(dateString){
         return dateString.slice(0, 6); 

Then you have this set to filter in the ng-repeat but putting it there it would need to return a filtered array, not a string input and manipulation. So it needs to be placed where you pass in a string

<li ng-repeat="date in dateArr">
        <span class="date">{{date | dateFormatter}}</span>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download