Add some undefined checks to your custom filters to prevent them breaking when bad/malformed/wrong type/data is passed to it.
For example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
app.filter('currentUserToTop', function () { return function (users, current) { if ( var newList = []; angular.forEach(users, function (u) { if (u.id == current) { newList.unshift(u); } else { newList.push(u); } }); return newList; }; }); |
Expects users to be an array and current to be a number (string for loose comparisons).
1 2 3 4 5 6 7 |
<ul> <li data-ng-repeat="u in users | currentUserToTop:user.id"> ... </li> </ul> |
1 2 3 4 |
users = users (array) current = user.id (number) |
If they were different format or undefined it would break horribly.
Different ways you can check.
1 2 3 4 5 6 |
// if (!angular.isUndefined(users) && !angular.isUndefined(user)) { ... ... |