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;
}