<h3>List <span ng-bind="filteredProducts.length"></span></h3>
<input type="text" ng-model="search.name" placeholder="name">
<div data-ng-repeat="product in filteredProducts =(products.productList | psearch:search.name)" class="productList">
//use the product info...
</div>
.filter('psearch',function(){
return function(element,searchname) {
console.log("psearch called");
console.log("element:",element);
var out = [];
angular.forEach(element, function(product) {
if (product.naam.match(searchname)) {
out.push(product);
}
});
console.log("out",out); //this gives me an array with the number of items matching the result
return out;
}
});
$scope.filteredProducts.lengthconsole.log("filtered:",typeof $scope.filteredProducts);
Hi Marco,
You controller runs before your template ‘runs’. add an ng-Change='triggerSomething' to your input. in the triggerSomething you will have the change to do what you want.
Best thing you can do is move the filteredProducts =(products.productList | psearch:search.name) part into that function, and have less logic in your template!
Is that enough for you?
Regards
Sander
angular.module('timers').filter('filterww',[ 'appdata', function(appdata){
return function(input,search,timerscontroller){
var out = [];
angular.forEach(input, function(timer){
if(search)
var descriptionLC = timer.description.toLowerCase();
searchLC = search.toLowerCase();
if(descriptionLC.match(searchLC)){
out.push(timer);
}
});
return out;
};
in my view i put an input with an ng-change attached to it that calls the filterTimers() function located in my controller
<input type="text" ng-model="timersCtrl.appdata.timer.queryww" placeholder="Description" data-ng-change="timersCtrl.filterTimers()">
function in controller:
self.filterTimers = function(){
var filter = function(){
self.filteredTimers = $filter('filterww')(self.appdata.timers, self.appdata.timer.queryww, self);
};
};
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/3QGdSHtpyY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.