I am presently playing around with some Angular examples that I found over here - http://ift.tt/1Cx5nJC
I am using the built in filterFilter filter (he he) and I have read that I may need to create my own filter (so I can pass params) however seems like I should not have to if the filter will just re-run. The idea I am working on is to try to let the user define the character that is used to filter the array.
My present code looks like so:
var myApp = angular.module('FilterInControllerModule', [])
.controller('FilterController', ['filterFilter', function(filterFilter) {
this.filterChar = 'a';
this.array = [
{name: 'Tobias'},
{name: 'John'},
{name: 'Jack'},
{name: 'Frank'},
{name: 'Desmond'},
{name: 'Allan'},
{name: 'Margie'}
];
this.filteredArray = filterFilter(this.array, this.filterChar);
}]);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Filters Extended Example 1</title>
</head>
<body ng-app="FilterInControllerModule">
<div ng-controller="FilterController as ctrl">
Filter by character: <input ng-model="ctrl.filterChar" type="text" maxlength="1"><br><br>
<div>
All entries:
<div ng-repeat="entry in ctrl.array">{{entry.name}}</div>
</div><br>
<div>
Entries that contain an "{{ctrl.filterChar}}":
<div ng-repeat="entry in ctrl.filteredArray">{{entry.name}}</div>
</div>
</div>
<script src="http://ift.tt/15MbGgT"></script>
<script src="script.js"></script>
</body>
</html>
If you run the code you will find that the two-way binding between the model and view is working between the controller and the expression {{ctrl.filterChar}} however the controller does not seem to re-evaluate the actual filtering. Why might this be?
Aucun commentaire:
Enregistrer un commentaire