angularjs - Angular filter with multiple checkboxes in separate filters -
i wrong because can't achieve result need.
my json data looks
[{ type_id: 1, brand_id: 0, name: 'title', description: 'description', img: 'url' },...]
so need filter data type_id
, brand_id
has not complicated task stuck lot , appreciate can't handle now.
and how view looks like. have 2 filters generated ng-repeat , ng-repeat devices need filter type , brand filter.
// filter 1 <div class="filters"> <h3 class="filters__title">choose type</h3> <div class="swiper-container"> <div class="swiper-arrow-prev"></div> <div class="swiper-arrow-next"></div> <div class="swiper-overflow"> <div class="swiper-wrapper filter" data-id="type"> <div class="swiper-slide filter__checkbox" ng-repeat="item in types"> <input type="checkbox" name="{{item.id}}" id="filter-{{item.id}}" ng-model="item.id" ng-checked="item.id"> <label for="filter-{{item.id}}"> <span>{{item.type}}</span> </label> </div> <!-- /item --> </div> <!-- /filter --> </div> </div> </div> <!-- /filters --> // filter 2 <div class="filters"> <h3 class="filters__title">choose brand</h3> <div class="swiper-container"> <div class="swiper-arrow-prev"></div> <div class="swiper-arrow-next"></div> <div class="swiper-overflow"> <div class="swiper-wrapper filter" data-id="brands"> <div class="swiper-slide filter__checkbox" ng-repeat="brand in brands"> <input type="checkbox" name="{{brand.id}}" id="brand-{{brand.id}}" ng-model="brand.id"> <label for="brand-{{brand.id}}"> <img ng-src="{{brand.img}}" alt=""> <span>{{brand.name}}</span> </label> </div> <!-- /item --> </div> <!-- /filter --> </div> <!-- /swiper-overflow --> </div> <!-- /swiper-container --> </div> <!-- /filters --> <div class="card" ng-repeat="device in devices"> <div class="card__wrap"> <figure> <img ng-src="{{device.img}}" alt=""> </figure> <!-- /img --> <h3 class="card__title">{{device.model}}</h3> </div> </div> <!-- /card --> angular.module('app', []).controller('mainctrl', ['$scope', 'datajson', '_', function($scope, datajson, _) { $scope.filtercontainer = []; // data datajson.getpromise().then(function(data) { $scope.brands = data.brands; $scope.devices = data.devices; $scope.types = data.device_types; return data.devices; }).then(function(data) { }) }])
you can use below code filter
// let take 2 input <input ng-model="type_id_model"><input ng-model="brand_id_model"> // filter 1 ng-repeat="item in types | filter:{type_id : type_id_model}" // filter 2 ng-repeat="brand in brands | filter:{brand_id : brand_id_model}"
Comments
Post a Comment