我为我的表达式构建了一个自定义过滤器。它以某种方式起作用。无论如何,我不断收到错误,我不明白为什么? 错误:“TypeError:无法读取 null 的属性‘split’”
这是我的过滤器:
LeadApp.filter("q_Filter", function () {
return function (input, splitChar, index) {
if (index === 1) {
q_a = input.split(splitChar);
return q_a[1];
}
else {
q_a = input.split(splitChar);
return q_a[0];
}
};
});
这是 View :
<tr ng-repeat="select in lead_selection" ng-show="select.length && $index > 4">
<td>
<i class="fa fa-circle-thin"></i>
<strong>{{ select | q_Filter:' | ':0 | uppercase }}</strong> <br />
<p class="p-l-1">{{ select | q_Filter:' | ':1 }}</p>
</td>
</tr>
最佳答案
在split
输入值之前,您应该检查input
是否为null
。
显示此错误是因为您的输入
为null
或空
LeadApp.filter("q_Filter", function () {
return function (input, splitChar, index) {
if(!input) {
return '';
}
if (index === 1) {
q_a = input.split(splitChar);
return q_a[1];
}
else {
q_a = input.split(splitChar);
return q_a[0];
}
};
});
关于javascript - Angular 自定义过滤器返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35962713/