AngularJs滤波器QUOT;错误而插值" [英] AngularJs filter "Error while interpolating"

查看:103
本文介绍了AngularJs滤波器QUOT;错误而插值"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我AngularJs过滤器我有以下几点:

Inside my AngularJs filter I have the following:

 return function(list){
      return list;
 }

这正常工作

但是,下面的抛出一个错误,而插值误差{{列表| FILTERNAME}} ...类型错误:名单是不确定的

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.

推荐答案

DotDotDot 已经回答的问题,但我想提高他的回答是:

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

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

更新角用户:

return function(list){
    return angular.isDefined(list) ? list.length : 0;
}

这篇关于AngularJs滤波器QUOT;错误而插值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆