Reputation: 91
I wrote test filter, that must return constant data.
mainApp.filter('dateParser', function () {
return function (param) {
return [{id:1,day:'23.07.17'},{id:2,day:'22.07.17'}];
};
});
However when I whant it like that:
<td ng-repeat="crrDay in studentOne.daysList|dateParser">
{{day.currentVal}}
</td>
I get these data but in console get an error:
Error: $rootScope:infdig
Infinite $digest Loop
Please tell me why this is happening?
UPDATE full filter
mainApp.filter('dateParser', function () {
console.log(this);
return function (param) {
var parse, sorted, result = [], parsedArray = [];
for (var i = 0; i < param.length; i++) {
parse = param[i].day.split('.');
parsedArray[i] = {
'id': param[i].id,
'day': parse[0],
'month': parse[1],
'year': parse[2]
};
}
sorted = _.sortBy(parsedArray, ['year', 'month', 'day']);
for (i = 0; i < sorted.length; i++) {
result[i] = {
id:sorted[i].id,
day: sorted[i].day + '.' + sorted[i].month + '.' + sorted[i].year
};
}
return result;
};
});
Upvotes: 1
Views: 43
Reputation: 222720
You are returning function inside a function, change your filter as,
mainApp.filter('dateParser', function () {
return [{id:1,day:'23.07.17'},{id:2,day:'22.07.17'}];
});
function(param)
does nothing here.
EDIT
If you need to accept a param, do it like this,
mainApp.filter("dateParser", function() {
return function(input) {
//do your process and return
};
})
Upvotes: 1