Error: this.filters.forEach is not a function
的forEach內提供服務AngularJS
.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
服務裏面?
看起來您在過濾器定義中有一個小的語法錯誤。注意最後一個屬性後面的','。 –
@TravisJ不錯,但不是很不幸。 –