javascript - AngularJS - Get value from non-input element to filter through list -
i'm trying retrieve value "li" element, depending on 1 user clicked on, responsible setting radius on map , display search results.
these values either 5,10,25,50 or 100. number needs passed custom filter filter search results.
html
<ul class="cf" id="filter"> <li ng-click="getradius(5)" class="current"><a href="#">5 km</a></li> <li ng-click="getradius(10)"><a href="#">10 km</a></li> <li ng-click="getradius(25)"><a href="#">25 km</a></li> <li ng-click="getradius(50)"><a href="#">50 km</a></li> <li ng-click="getradius(100)"><a href="#">100 km</a></li> </ul>
on search results, further down, want call filter.
<li ng-repeat="store in stores | orderby:'-d':true" ng-click="storelistclick(store)"> <h3>{{ store.store_name }} <small>{{store.d}}km</small></h3> <p>{{ store.address1 }}, {{ store.address2 }} <br> {{ store.city }}</p> </li>
app.js
$scope.getradius = function(radius) { console.log(radius); // correctly gets radius value /* how make custom filter here??? */ }
inside custom filter compare distance between searched query , store location. i'm not sure if correct way go this, or whether i'm on complete wrong track.
essentially not know how pass value non-input element angular filter.
you don't need retrieve value element. can have current radius value saved in controller , use either filter store list immediately, or in custom filtering function. custom filter this.
angular.module('test', []).controller('main', ['$scope', function ($scope) { var currentradius = 100; $scope.getradius = function (r) { currentradius = r; }; // custom filter $scope.radius = function (store) { return store.distance <= currentradius; }; //other stuff... }]);
you can use filtering function in html this:
<ul> <li ng-repeat="store in stores | filter: radius">some store data</li> </ul>
you can check out example here
Comments
Post a Comment