In my project, I am working with an array ($scope.names) that contains simple objects. I have implemented functions to clean the values from diacritics and when I console.log the result, it appears correct. For example, 'La 45 km nord- vest de Bucureşti' becomes 'La 45 km nord- vest de Bucuresti' after cleaning.
I have also applied the same method to another variable ($scope.searchText) to ensure that the searchable text is compatible. So far, everything seems to be working fine.
However, I am facing an issue where even though I have standardized the values of these two variables, the filtering process is not functioning properly. When I try to search for 'Bucures', it does not display the object that contains the cleaned word 'Bucures' (original word 'Bucureş')...
What could I possibly be doing wrong in this scenario?
The complete code can be found here: http://plnkr.co/edit/D5WfiOGd5I3QfcNVdOmr?p=preview
This is the angular script being used:
var app = angular.module('myApp', []);
app.controller('namesCtrl', function($scope, $filter) {
$scope.names = [
{
"adresa": "Str. Calafatului nr. 10",
"latitudine": "44.1",
"localitatea": "GALICEA MARE",
"longitudine": "23.3",
},
{
"adresa": "bd. Elisabeta nr. 1",
"latitudine": "44.170901",
"localitatea": "CONSTANŢA",
"longitudine": "28.663195",
},
{
"POTLOGI": "La 45 km nord- vest de Bucureşti",
"latitudine": "44.564319",
"localitatea": "POTLOGI",
"longitudine": "25.588091",
}
]
$scope.searchText = "";
$scope.searchCleanText = "";
$scope.myFilter = function (items) {
for (var i = 0; i < items.length; i++) {
var boolChk = false;
angular.forEach(items[i], function (value, key) {
var cleanValue = removeDiacritics(value).toLowerCase();
if (boolChk === false) {
boolChk = cleanValue.includes($scope.searchCleanText);
}
console.log(value + ' ' + cleanValue.includes($scope.searchCleanText) + '\tboolChk = ' + boolChk);
return boolChk;
});
}
}
$scope.$watch('searchText', function() {
$scope.searchCleanText = removeDiacritics($scope.searchText).toLowerCase();
$scope.showItems = $filter('filter')($scope.names, $scope.searchText, $scope.myFilter($scope.names));
console.log($scope.showItems);
});
});