Lock Lock - 7 months ago 36
AngularJS Question

Angular filter throwing "Can't interpolate" error even though the filter works

I have the below filter (why I got from StackOverflow) which works on one page, but throws the below error on another (using the same object).

app.filter('dateFormat', function dateFormat($filter){
return function(text){
var tempdate= new Date(text.replace(/-/g,"/"));
return $filter('date')(tempdate, "dd-MM-yyyy");

Can't interpolate: {{ job.job_date | dateFormat}}
TypeError: text is undefinedO/<@http://localhost/ef-serial-numbers/public/assets/global/plugins/angularjs/angular.min.js:6:412Ka.interr@http://localhost/ef-serial-numbers/public/assets/global/plugins/angularjs

If I change
to a hardcoded date, the error disappears. The thing is, the filter is actually working correctly regardless of the error.


Maybe check if text is undefined before calling .replace.

Since at the very beginning, the filter function may be called before job.job_date gets its value.