javascript - Angular - 将更多项目加载到列表中

标签 javascript html angular typescript

我是 Angular 的新手,我正在尝试在我的项目上做一些类似 loadMore 或 ShowMore 按钮的事情,我被困在这里,所以和你们在一起知道一些可以帮助我的事情,我将不胜感激。

我有一个包含 10 个元素的列表,如果我的用户超过 10 个,我们将有一个 showMore 按钮来单击并加载这些其他元素。

我正在尝试如何做到这一点,但这是我的第一个项目,我对此感到困惑。

<div fxFlex fxLayout="row" fxLayoutAlign="center center" style="padding-top: 16px;">
<button (click)="showMore()" mat-button color="accent" style="width: 100%" value="bold">Show More</button>
</div>

showMore(){

this.pageSize = this.pageIndex + 1;

this.get(10, this.pageIndex, 'Recents'); 
}

直到这一刻,我都在尝试更改当前的 pageIndex 并移动到包含其他元素的下一个。我的索引开始是 0。“最近”是我要过滤的报告状态。

最佳答案

模板:

<div *ngFor="let item of items">
  msg{{item}}
</div>

<input type="button" (click)="LoadMore()" value="showMore">

组件:

currentIndex = 10;
items = [...Array(currentIndex).keys()];

constructor(private crd: ChangeDetectorRef){}

LoadMore(){
  currentIndex += 10;
  this.items = [...Array(currentIndex).keys()];
  this.cdr.detectChanges();
}

关于javascript - Angular - 将更多项目加载到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53280037/

相关文章:

javascript - jQuery .animate 函数不起作用

python - 如何打印关键字后的所有内容?例如打印单词 "Apple"和单词 "Pen"之间的所有内容

angular cli 必须使用 import 来加载 ES 模块

html - Angular 4 使用箭头键从文本字段滚动到 <li>

javascript - 如何将整个 JSON 响应转换为值数组

javascript - "Uncaught TypeError: Cannot read property ' 添加事件监听器 ' of null"

html - Bootstrap 右边的额外空间

javascript - 如何在整个 Web 应用程序堆栈中利用 Haskell 类型安全?

javascript - jQuery 不处理事件

javascript - 如何在面板标题上只显示超棒的字体图标?