Angular 2+ - check if Pipe returns an empty subset of original list

前端 未结 7 1352
天涯浪人
天涯浪人 2021-02-04 02:37

I have a list of strings that I want to iterate through, but I want to be able to filter them using a search term. Like this:

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 03:11

    This is my code which modified a bit from @Günter Zöchbauer

    No item found
    {{ item }}

    Pipe code

    @Pipe({
      name: 'FilterItem'
    })
    export class FilterItem {
    
      transform(list, args?) {
           let result = ...; 
           if ( result && result.length > 0 ){
              return [ result ];
           }else{
              return [ -1 ];
           }
      }
    }
    

提交回复
热议问题