angular - 如何使用由http请求填充的数组进行分页| 角 6
问题描述
我在ngOnInit
. 以下是我的看法
<mat-grid-list cols="4" rowHeight="150px">
<mat-grid-tile *ngFor="let item of lubricants; let i = index">
<img src="../assets/icons/washingIcons/upArrow.png">
</mat-grid-tile>
</mat-grid-list>
这是我的 ts 文件:
import { Component, OnInit } from '@angular/core';
import { SellLubricantsService} from './sell-lubricants.service'
@Component({
selector: 'app-sell-lubricants',
templateUrl: './sell-lubricants.component.html',
styleUrls: ['./sell-lubricants.component.scss']
})
export class SellLubricantsComponent implements OnInit {
lubricants:any;
constructor(private sellLubServ:SellLubricantsService) { }
ngOnInit() {
this.getAllLubricants();
}
getAllLubricants(){
this.sellLubServ.getAllLubricants().subscribe(
Response=>{this.lubricants=Response;},
error=>{alert("error")}
);
}
}
这可以很好地用包含 100 个项目的图块填充我的页面,但我需要通过设置页面来防止在数组变得更大(如 1000 个项目或更多)时加载所有数据。非常感谢您的帮助,我尝试遵循角度文档,但我不知道如何根据需要应用它。我已经导入了所需的模块。
解决方案
如果您想防止一次加载超过 100 个项目,那么这就是需要从后端处理的事情。它不是你应该从角度管理的东西。您的服务不必担心它获得了多少对象。如果您不介意一次加载很多对象并且在显示它们时只需要分页,这可能是一个简单的修复https://www.npmjs.com/package/ngx-pagination
推荐阅读
- android - Fragment 类、MVVM、Viewmodel 中未解析的引用(vars)
- java - 一个方法可以有不止一种类型的输入吗?
- php - PHP if else 语法问题,需要帮助纠正它
- javascript - 如何通过搜索值而不是键来删除 localStorage 键对值?
- .net - Alglib minnlc 不受约束地返回答案
- python - Python DataFrame:根据自定义值将数据拆分为行?
- javascript - 如果用户使用 onbefoerunload 导航,如何在 jexcel 单元格中发生更改时发出警报
- python - Keras acc 和 val_acc 不会改变
- r - 如何为 R Shiny 中的单个 fileInput() 分配不同的进程给 selectInputs() 的给定组合?
- python - 在 Python 中解决问题以在团队中分配多个项目