My custom filter should output:
Mark
...however it's outputting:
- M
- a
- r
- k
Here's my view:
<body ng-controller="MainCtrl">
<ul>
<li ng-repeat="friend in friends | myFriend:currentUser">
{{ friend }}
</li>
</ul>
</body>
...and controller:
var app = angular.module('plunker', []);
app.filter('myFriend', function () {
return function (items, currentUser) {
console.log(items);
console.log(currentUser);
for (var i = 0; i < items.length; i++) {
if (items[i] === currentUser) {
return items[i];
}
}
};
});
app.controller('MainCtrl', function($scope) {
$scope.currentUser = 'Mark';
$scope.friends = ['Andrew', 'Will', 'Mark', 'Alice', 'Todd'];
});
Here is my Plunker: http://plnkr.co/edit/JCKAt05MPlrvIZBCGO0n?p=preview
How can my custom filter output "Mark"?