Filter data on click function in AngularJS -


i have data on bikes in html page. have filter data via on click function. have used filter in text box area, want same functionality via on click function.

so how can bind filter click function?

http://jsfiddle.net/3g7kd/114/

<div ng-app='app' class="filters_ct">     <ul class="nav" ng-controller="selectfilter">         <li ng-repeat="filter in filters" ng-click="select($index)" ng-class="{sel: $index == selected}">             <span class="filters_ct_status"></span>             {{filter.name}}              <ul class="subul" ng-if=filter.lists.length>                 <li ng-repeat="list in filter.lists" ng-click=" $event.stoppropagation()">                   <input type="checkbox">  {{list}}                 </li>             </ul>         </li>     </ul>     <input type="text" ng-model="search">     <div ng-controller="listctrl">         <div class="list" ng-repeat="list in lists | filter:{brand:search}">             {{list.brand}}             {{list.year}}         </div>          </div>  </div> 

angular

var app = angular.module('app', []);   app.controller('selectfilter', function($scope) {      $scope.filters = [             {                 "name": "brand",                 'lists': ['yamaha','ducati','ktm','honda']             },             {                 'name': "year",                 'lists': [2012,2014,2015]             }         ];     $scope.selected = 0;      $scope.select= function(index) {        if ($scope.selected === index)             $scope.selected = null        else            $scope.selected = index;      }; });   app.controller('listctrl', function($scope) {      $scope.lists = [             {                 "brand": "ducati",                 'year': 2012             },             {                 'brand': "honda",                 'year': 2014             },             {                 'brand': "yamaha",                 'year': 2015             },             {                 'brand': "ktm",                 'year': 2012             }         ];  }); 

you knew how use filter when given object within partial. moved 1 of controllers have outer , inner controller.

<div ng-app='app'ng-controller="mainctrl mainctrl">      <div ng-controller="listctrl">          <!-- filter object accessible here -->     </div>  </div> 

i added scope variable outer controller $scope.activefilters (filling should able on own, see plunker 1 possible solution.

this object changed when clicking on checkboxes. $scope.activefilters accessible inner controller can pass filter before:

<div class="list" ng-repeat="list in lists | filter:activefilters">      {{list.brand}}      {{list.year}} </div> 

note there nicer solutions (using checkbox model among other things).

working plunker: http://jsfiddle.net/ywfrbgoq/


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -