So I have read this: how to use custom filter in angularjs which has got me this far. and I didn't want to re-open as it is 3 years old.
the problem I am getting is this, this is copied from the chrome debugger in elements view, it has commented out my loop and filter so nothing has happened on screen.
<!-- ngRepeat: person in $ctrl.people | icfilter:W -->
My app and filter
var app=angular.module("componentApp", []);
app.filter('icfilter', function() {
return function(people, filterBy) {
var out = [],
lowerFilter = filterBy.toLowerCase();
angular.forEach(people, function(person) {
if (person.name.toLowerCase().includes( lowerFilter)){
out.push(person);
}
});
return out;
}
});
the html template
<!DOCTYPE html>
<html>
<head>
<script src="angular/angular.min.js"></script>
<script src="app/component.js"></script>
<script src="app/namesList.component.js"></script>
<meta charset="ISO-8859-1">
<title>Components</title>
</head>
<body>
<div ng-app="componentApp">
<names-list></names-list>
</div>
</body>
</html>
and lastly my component
angular.module("componentApp").component("namesList",{
template: '<div >' +
'<h4>Family members:</h4>'+
'<li ng-repeat="person in $ctrl.people | icfilter:W">{{ person.name +", " + person.age }}</li>'+
'</div>',
controller: function namesListController(){
this.filterBy="W";
this.people = [ {
age : 46,
name : 'Wendy'
}, {
age : 50,
name : 'Joe'
}, {
age : 11,
name : 'Frank'
}, {
age : 6,
name : 'Jenny'
} ];
this.sort='name';
}
});