Angular 2 filter/search list

前端 未结 12 1397
眼角桃花
眼角桃花 2020-11-27 14:25

I\'m looking for the angular 2 way to do this.

I simply have a list of items, and I want to make an input whos job is to filter the list.



        
12条回答
  •  囚心锁ツ
    2020-11-27 14:52

    HTML

    
    
    {{item.name}}

    Component

    search(): void {
        let term = this.searchTerm;
        this.items = this.itemsCopy.filter(function(tag) {
            return tag.name.indexOf(term) >= 0;
        }); 
    }
    

    Note that this.itemsCopy is equal to this.items and should be set before doing the search.

提交回复
热议问题