Having an issue with filtering data from a JSON file that contains an array of 20 objects.
Within my factory, I have implemented two functions:
function fetchData() {
return $http
.get('mock.json')
.success(_handleData)
.error(_handleError);
}
function _handleData(data) {
var filteredData = _filterByProperty(data, "name", "XYZ");
console.log('filteredData', filteredData);
return filteredData;
}
When I check the console.log("filteredData"), it only displays the filtered elements (3 out of 20);
In a service, there is an ng-click function which does the following:
var applyFilter = function () {
DataFactory
.fetchData(_address)
.success(_handleServiceData);
}
where
var _handleServiceData = function (data) {
filteredData = data;
};
The question arises - why does the 'data' in _handleServiceData display all the elements instead of the previously filtered ones?
edit: Link to the plunk for reference - results are visible in the console