0

I have a filter in place, if the filtered results for criteria is >0, i get the results displayed. In the case where the criteria itself returns an empty list, well, i'll juts get an empty list else, i returns all items.

Id' like to adapt my code so that if a criteria is selected but outputs an empty list, it should rpint on screen a DIV initially set in display:none

I am thinking about putting an if/else statement within the second else, but could not get the right syntax...or may be it is juts a bad idea ?

.filter('selectedDishType', function() {
    return function(dishes, dishTypes) {
        console.log(dishTypes);
        if (dishTypes.length > 0) {
            return dishes.filter(function(dish) {
                return dishTypes.indexOf(dish.dishCategory.toLowerCase()) != -1;
            });
        } else {

            return dishes;

        }
    };
})
cdosborn
  • 3,111
  • 29
  • 30
lauWM
  • 659
  • 3
  • 10
  • 18

1 Answers1

0

create a small function which check dishType and call that function in if condition.

function isEmpty(dishType) {
    return (dishType && dishType.length > 0);
}

For checking value is blank or not please refer this question

Community
  • 1
  • 1
Nehal
  • 1,004
  • 1
  • 10
  • 33
  • thanks Nehal, though I dont' see where to embeed the function as I am just beginning in JS . – lauWM Mar 25 '15 at 13:52