Filtering nested objects in ng-repeat with a search input field

后端 未结 2 1541
难免孤独
难免孤独 2020-12-10 19:00

I am trying to filter nested objects in ng-repeat by using a search textbox.

Given the following object:

$scope.items = {
    \"1\": {
        name:          


        
2条回答
  •  自闭症患者
    2020-12-10 19:27

    If you don't need to reuse your filter anywhere else, you can write your filtering function in controller.

    scope.customSearchFilter = function(term){
        return function(item) {
            var regex = new RegExp(term || '', 'i');
            return regex.test(item.name + '');
        };
    };
    

    Filter argument is a single item, not an array.

    Here is examples. 1st variant is with model, and 2nd with plain scope:

    https://plnkr.co/edit/ELH8S5GymG8cHfOJqD9G

提交回复
热议问题