【发布时间】:2017-05-12 10:01:10
【问题描述】:
这确实是我的问题。我有一个按钮可以清除所有过滤器,但我只希望在使用任何过滤器时显示它。我怎样才能做到这一点?我需要在使用范围过滤器或过滤器酒店时出现。谢谢!!
清除过滤器的按钮
.filterheader
.filter-ctn
.filterheader
h4 Filtrar
span(class="delete-filter" ng-click="$ctrl.hotelsResultController.$onInit()")<i class="fa fa-times" aria-hidden="true"></i> Eliminar Filtros
.filtercontainer
hotel-root-component.js
(function () {
'use strict';
angular
.module('hotelsResult')
.component('hotelsRoot', {
bindings: {},
controller: hotelsResultController,
templateUrl: "hotel-result/hotels-root.html"
});
hotelsResultController.$inject = ['hotelsService'];
function hotelsResultController(hotelsService) {
const self = this;
self.filterOnHotels = [];
this.$onInit = function () {
hotelsService.getHotels().then(function (hotels) {
self.hotels = hotels;
self.filterOnHotels = hotels;
});
this.filters = {
"name" : "",
"targetName" : "",
"price":{
"priceMin" : 0,
"priceMax": 3250,
},
"stars":{
"all": true,
"five": false,
"four": false,
"three" : false,
"two" : false,
"one" : false
},
}
};
this.getHotels = function () {
return self.filterOnHotels;
};
}
})();
filter-header.component.js
(
function (){
'use strict';
angular
.module('filters')
.component('filterHeader', {
bindings:{},
require: {
hotelsResultController : '^hotelsRoot'
},
controller: filterHeaderController,
templateUrl: "hotel-result/filters/filterheader/filterheader.html"
});
function filterHeaderController() {}
})();
filter-hotel.component.js
(function (){
'use strict';
angular
.module('filters')
.component('filterHotel', {
bindings:{
"filters" : '<'
},
templateUrl: 'hotel-result/filters/filterhotel/filterhotel.html'
}).filter('filterHotel', function() {
var self = this;
return function (hotels,targetName) {
return hotels.filter(function (hotel) {
return hotel.name.toLowerCase().indexOf(targetName.toLowerCase()) != -1;
})
}
})
})();
filter-range.component.js
(function (){
'use strict';
angular
.module('filters')
.component('filterNight',{
controller: filterNightController,
require: {
hotelsResultController : '^hotelsRoot'
},
bindings:{
"filters" : '<'
},
templateUrl: "hotel-result/filters/filternight/filternight.html"
}).filter('filterNight',function () {
return function (hotels,price) {
return hotels.filter(function (hotel) {
return (hotel.price >= price.priceMin && hotel.price <= price.priceMax);
});
}
});
function filterNightController (){
let self = this;
this.slider = {
value: 150,
options: {
minRange: 200,
noSwitching: true,
pushRange: true,
onChange : this.filterNight
}
};
}
})();
item-list.jade
ul
li(ng-repeat="hotel in $ctrl.hotels | filterHotel: $ctrl.filters.targetName | filterStar: $ctrl.filters.stars | filterNight: $ctrl.filters.price")
item(item='hotel')
【问题讨论】:
标签: javascript angular filter