1

Inside my AngularJs filter I have the following:

 return function(list){
      return list;
 }

That works fine

However, the following throws an error of "Error while interpolating {{ list | filterName}}...TypeError: list is undefined"

 return function(list){
      return list.length;
 }

What is happening that is causing list to be undefined for a brief moment when this function runs, or what can I do to fix this issue. The value still gets returned, I just have a nasty error in console.

1
  • 4
    it happens when angularJs is bootstrapping the page, for a brief moment (between the moment it starts and the moment it actually reaches this part of your page) the value will be undefined, you can simply do if(typeof(list) != undefined){return list.length;} Commented Aug 20, 2013 at 13:48

1 Answer 1

2

DotDotDot already answered question, but I'd like to improve his answer:

return function(list){
    return (typeof(list) !== 'undefined') ? list.length : 0;
}

Update for Angular users:

return function(list){
    return angular.isDefined(list) ? list.length : 0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.