javascript - Filter not working on ng-repeat using dropdown options -
i'm trying filter out table using values in dropdowns (system & equipments). whenever try applying filter ng-repeat
data table disappears. have applied ng-model
values equipment , system dropdowns shown below. want use filter narrow down information in table. have provided necessary code along screenshots of data.
html
<div class="row"> <div class="form-group col-xs-6" id="syslist"> <label for="selectsys">select system list:</label> <select class="form-control" id="selectsys" data-ng-model="system"> <option value="" disabled="" selected="" style="display: none">list of systems</option> <option ng-repeat="d in data">{{d.$id}}</option> </select> </div> <div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6" id="equiplist"> <label for="date">select date</label> <input type="text" class="form-control" id="date" placeholder="day, month, year" onfocus="(this.type='date')" data-ng-model="date"/> </div> </div> <div class="row"> <div class="form-group col-xs-6" id="equiplist"> <label for="selectequ">select equipment list:</label> <select class="form-control" id="selectequ" data-ng-model="equipment"> <option value="" disabled="" selected="" style="display: none">list of equipments</option> <option data-ng-repeat="eq in allequipments track $index">{{eq}}</option> </select> </div> <div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6" id="type"> <label for="searchtype">search type:</label> <select class="form-control" id="searchtype" data-ng-model="type"> <option value="" disabled="" selected="" style="display: none">select type of maintenance</option> <option>corrective maintenance</option> <option>preventive maintenance</option> <option>standby</option> </select> </div> </div> <hr/> <div class="table-responsive"> <table class="table table-striped table-hover"> <tr> <th id="system">system</th> <th id="equipment">equipment</th> <th id="date">date</th> <th id="type">type</th> </tr> <tr data-ng-repeat="d in allequipments | filter: equipment | filter: system"> <td headers = "system">{{allsystems[$index]}}</td> <td headers = "equipment">{{d}}</td> <td headers = "date">date</td> <td headers = "type">standby</td> </tr> </table> </div> </div>
js
/*global angular*/ var app = angular.module('sdt', ['ngroute', 'firebase']); app.config(['$routeprovider', function ($routeprovider) { 'use strict'; $routeprovider.when('/sdt', { templateurl: 'searchdowntime/sdt.html', controller: 'sdtctrl' }); }]); app.controller('sdtctrl', ['$scope', '$firebaseobject', '$firebasearray', function ($scope, $firebaseobject, $firebasearray) { 'use strict'; $scope.allsystems = []; $scope.allequipments = []; var ref = firebase.database().ref(); var data = ref.child("data"); var list = $firebasearray(data); list.$loaded().then(function(data) { $scope.data = data; angular.foreach ($scope.data , function (d) { angular.foreach (d.equipments, function (e) { $scope.allsystems.push(d.$id); $scope.allequipments.push(e.equipment); console.log($scope.allequipments); console.log($scope.allsystems); }) }); console.log($scope.data); }).catch(function(error) { $scope.error = error; }); $scope.onsystemchange = function(item){ } }]);
i suggest call function onchange of dropdown, in function filter list allequipments(copy of allequipments) , use copied list in ng-repeat.
Comments
Post a Comment