javascript - Angular custom filter and indexOf condition -
i'm new computers , trying build custom filter angularjs app.
i have search string of intergers (cultivos.age) , return item if string contains mes.age condition. i've managed make workingfilter returns == values. can't manage write 'indexof' condition returns item if mes.age contained in cultivos.age array
the working filter:
angular.module('calendariofilters',[]).filter('filtromes', function(){ return function(cultivos, name){ var arraytoreturn = []; (var i=0; i<cultivos.length; i++){ if (cultivos[i].age == this.mes.age) { arraytoreturn.push(cultivos[i]); } } return arraytoreturn; };
});
and not working filter:
angular.module('calendariofilters',[]).filter('filtromes', function(){ return function(cultivos, name){ var arraytoreturn = []; (var i=0; i<cultivos.length; i++){ if (cultivos[i].age.indexof(this.mes.age) !== -1) { arraytoreturn.push(cultivos[i]); } } return arraytoreturn; };
});
i'm calling filter in html
<li ng-repeat="cultivo in cultivos | filtromes:''">
console logs "typeerror: cannot read property 'length' of undefined" in working filter.
thanks!
change line:
if (item.age.indexof(this.mes.age) >= -1) {
to:
if (item.age.indexof(this.mes.age) !== -1) {
hope helps.
Comments
Post a Comment