我为我的表达式构建了一个自定义过滤器。它以某种方式工作。无论如何,我一直得到一个错误,我无法弄清楚为什么? 错误:“TypeError:无法读取属性'split'为null”
这是我的过滤器:
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];
}
};
});
以下是观点:
<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>
答案 0 :(得分:2)
您应该在input
输入值之前检查null
是否为split
。
显示此错误是因为您input
为null
或empty
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];
}
};
});
答案 1 :(得分:0)
在调用
之前,只需检查输入必须具有某些值的输入input.split(splitChar)
还有一件事要确保输入包含splitChar