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
服务中使用?