javascript - How to pass input values as arguments into the custom filter in Angularjs -
i want pass 2 argument custom filter 'from' , 'to' custom filter have created in controller.
here can see custom filter have created:
vm.filterminutes = function (prop, from, to) { return function (item) { return item[prop] >= && item[prop] <= to; }; };
and view looks this:
<label>search from: <input ng-model="fromminutes"></label> <label>search from: <input ng-model="tominutes"></label> <tr style="cursor: pointer;" ng-repeat="student in adminreportsworksnaps.data | filter: adminreportsworksnaps.filterminutes('totalminutes', fromminutes,tominutes)"> <td>{{ student.studentid }}</td> <td>{{ student.firstname }}</td> <td>{{ student.lastname }}</td> <td>{{ student.municipality }}</td> <td class="total success">{{ student.totalminutes | number}}</td> </tr>
for reason not working. well, if call filter this: filter: adminreportsworksnaps.filterminutes('totalminutes', 5000,6000)"
works fine.. cant see how can pass input values textboxs.
thanks
pass :
separated (assuming using controlleras
pattern vm
alias)
ng-repeat="student in adminreportsworksnaps.data | filter: adminreportsworksnaps.filterminutes: 'totalminutes': fromminutes: tominutes"
so in above case need expect 4 parameter in filter, 1st parameter adminreportsworksnaps.data
, 2nd totalminutes
, 3rd fromminutes
& last tominutes
value
vm.filterminutes = function (collection, prop, from, to) { //collection have console.log("adminreportsworksnaps.data", collection) console.log(prop, from, to); return (collection || []).filter(function (item) { return item[prop] >= && item[prop] <= to; }); };
Comments
Post a Comment