I'm struggling with an if-else block in my code that is not getting executed as expected. Despite rearranging the code to ensure the if-else condition is met before calling http.get(), I am still facing issues. This problem arises while working with AngularJS.
//controller
function search($scope, $http, $location)
{
function parse(item)
{
if(item.match(/str1/g))
{
item = item.replace(/str1/g, 'one');
}
else if(item.match(/str2/g))
{
item = item.replace(/str2/g, 'two');
}
else if(item.match(/str3/g))
{
item = item.replace(/str3/g, 'three');
}
//and so on
return item;
}
$http.get('/search='+ parse($location.search().query.toLowerCase()))
.success(function(data) {
$scope.count = data.length;
$scope.items = data;
$scope.exists = data.length > 0;
})
.error(function(err) {
});
}