Error: this.filters.forEach is not a function
.provider('searchFilter', function() {
this.filters = {
location : {
default: 'Boston, MA',
value: ''
},
radius : {
default: '1',
value: ''
}
}
this.$get = function() {
var filters = this.returnFilters();
return {
returnFilters: function() {
return filters;
}
}
};
this.setLocation = function(location) {
this.filters.location.default = location;
};
this.setRadius = function(radius) {
this.filters.radius.default = radius;
};
this.returnFilters = function() {
this.filters.forEach(function (filter) {
filter.value = (filter.value=='')?filter.default:filter.value;
});
return this.filters;
};
});
为什么我不能在forEach
服务中使用.provider
?
答案 0 :(得分:0)
filters
是一个对象,它没有“forEach”方法。但是,您可以使用for(.. in ..)
或Object.keys(..).forEach
(或者我认为甚至angular.each
)