【发布时间】:2019-05-17 22:28:58
【问题描述】:
我需要帮助。 我是 Angular 的新手,我正在使用 Angular 7,最新版本。
所以我的 Html 代码:
<input type="text" class="form-control" (input)="onSearchChange($event.target.value)" placeholder="Search serial...">
我的组件.ts
onSearchChange(searchValue: string) {
//alert(searchValue);
console.log(searchValue);
this.filteredItems = this.listaTest; //uno un array di appoggio per la ricerca real-time
this.filteredItems.subscribe(
(response) => {
console.log(response);
this.filteredItems = response.filter(x => x.seriale.startsWith(searchValue));
});
}
我的<ul>名单:
<ul class="list-group" style="width:80%; margin:0 auto; font-weight: bold; margin-top: 2%;">
<li *ngFor="let item of filteredItems | async" class="list-group-item">{{item.seriale}}
<button style="float:right;">{{item.seriale}}Download certificati</button>
</li>
</ul>
我的目标是在用户搜索时实时更新<ul> 列表。
所以我尝试了一个数组,而不是 Observable,我只是推动并删除并完成。
但是,使用 Observable,我如何实时更新列表?和过滤一样吗?
谢谢
【问题讨论】:
标签: angular filter rxjs observable angular7