首页 > 解决方案 > 当我通过任何事件调用 API 时,它会在 ANGULAR 2+ 中滚动窗口顶部?

问题描述

我在一个组件上有一个按钮,可以在这样做时过滤我的表格,因此我正在调用 API。调用 API 后,它会从顶部滚动到窗口。但我希望它应该保持在原来的位置。

注意事项:我没有使用滚动 CSS 或任何 javascript。

.ts 文件

 ngOnInit() {
    this.type = 'all';
    this.getCandidateDetails(this.type);
 }

 getLoggedInuserDetails(type) {
    this.sharedService.getCandidateDetails(type).subscribe(res => {
      this.User = res.data;
    });
 }

 getFemaleCandidateDetails(){
    this.type = 'female';
    this.getCandidateDetails(this.type);
 }

.html 文件

<button type="button" class="btn btn-primary" (click)="getFemaleCandidateDetails()">Overall</button>
<table>
// Here I am rendring the data
</table>

标签: javascriptangulartypescripteventsscroll

解决方案


推荐阅读