我的角度应用程序中存在一些问题。如果我尝试使用我的过滤器“formatPhone”
myApp.filter('formatPhone', function () {
return function (phone) {
if (!phone.length) {
return ' ';
}
var offset = 0;
var split = [];
if (phone.length === 10) {
split.push(3, 3, 2, 2);
} else if (phone.length === 7) {
split.push(0, 3, 2, 2);
} else {
split.push(0, 2, 2, 2);
}
var frag = [];
for (var i = 0; i < split.length; i++) {
frag.push(phone.substr(offset, split[i]));
offset += split[i];
}
return ((!frag[0]) ? '' : '(' + frag[0] + ') ') + frag[1] + '-' + frag[2] + '-' + frag[3];
}
});
为此:
<tr ng-repeat="member in userlist | orderBy: 'name && group'">
<td>{{member.name}}</td>
<td>{{member.group}}</td>
<td>{{member.team}}</td>
<td>{{member.post}}</td>
<td>{{member.phones.cdma || member.phones.home}}</td>
<td>{{member.phones.mob | formatPhone}}</td>
</tr>
我在控制台日志中遇到错误(angular.min.js:84),它对象'member'中的每个元素重复,但“formatPhone”函数有效。我该如何解决?
upd:错误如
Error: [$interpolate:interr] http://errors.angularjs.org/1.2.9/$interpolate/interr?p0=%7B%7Bmember.phones.mob%20%7C%20formatPhone%7D%7D&p1=TypeError%3A%20phone%20is%20null F/<@http://localhost/vendors/angular.min.js:6 qd/this.$get</g/s@http://localhost/vendors/angular.min.js:74 Bd/this.$get</h.prototype.$digest@http://localhost/vendors/angular.min.js:100 Bd/this.$get</h.prototype.$apply@http://localhost/vendors/angular.min.js:103 Zb/c/<@http://localhost/vendors/angular.min.js:18 d@http://localhost/vendors/angular.min.js:30 Zb/c@http://localhost/vendors/angular.min.js:18 Zb@http://localhost/vendors/angular.min.js:18 Tc@http://localhost/vendors/angular.min.js:17 @http://localhost/vendors/angular.min.js:201 o.Callbacks/j@https://code.jquery.com/jquery-2.1.0.min.js:2 o.Callbacks/k.fireWith@https://code.jquery.com/jquery-2.1.0.min.js:2 .ready@https://code.jquery.com/jquery-2.1.0.min.js:2 r...