你好,我希望你很好,我有一个组件允许用户按标签搜索文件,我使用 ngx-pagination 进行分页。当我在第一页时,我可以搜索所有文件,但是当我移动到其他页面时,搜索总是不计算上一页,只有搜索方法适用于下一页。但他给我的页码包含这个标签。
但我希望他出示包含文件的卡片。 下面的2张照片让事情更清楚
我的组件.TS:
export class AfficherComponent implements OnInit {
SearchTag: String;
files = [];
constructor(private uploadService: UploadFileService) {}
ngOnInit() {
this.reloadData();
}
reloadData() {
this.uploadService.getFilesList().subscribe((data) => {
this.files = data;
});
}
Search() {
if (this.SearchTag != "") {
this.files = this.files.filter((res) => {
return res.tag
.toLocaleLowerCase()
.match(this.SearchTag.toLocaleLowerCase());
});
} else if (this.SearchTag === "") {
this.ngOnInit();
}
}
}
我的组件.HTML
<div id="pricing-table" class="clear" data-aos="fade-right">
<div class="sel">
<div class="row">
<div class="col" style="left: -160px;">
<input
type="text"
placeholder="Search..."
[(ngModel)]="SearchTag"
(input)="Search()"
style="margin: 20px;"
/>
<div id="toggle" style="left: 450px;"></div>
</div>
</div>
</div>
<div
class="plan"
*ngFor="let file of files | paginate: { itemsPerPage: 3, currentPage: p }"
>
<h3></h3>
<button class="btn" style="background-color: #09c0a3;">Ouvrir</button>
<ul>
<li><b>Name: </b> {{ file.nom }}</li>
<li><b>Type: </b> {{ file.type }}</li>
<li><b>Departement: </b>{{ file.departement }}</li>
<li><b>Tag: </b>{{ file.tag }}</li>
</ul>
</div>
<pagination-controls
(pageChange)="p = $event"
style="float: right;"
></pagination-controls>
</div>