Javascript 每当我通过任何事件调用API时,它都会以角度2+;滚动窗口顶部;?

Javascript 每当我通过任何事件调用API时,它都会以角度2+;滚动窗口顶部;?,javascript,angular,typescript,events,scroll,Javascript,Angular,Typescript,Events,Scroll,我在一个组件上有一个按钮,当我调用API时,它会过滤我的表。调用API后,将其向上滚动到窗口。但我希望它应该保持原来的位置 注意:我没有使用滚动CSS或任何javascript .ts文件 ngOnInit() { this.type = 'all'; this.getCandidateDetails(this.type); } getLoggedInuserDetails(type) { this.sharedService.getCandidateDetail

我在一个组件上有一个按钮,当我调用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);
 }
<button type="button" class="btn btn-primary" (click)="getFemaleCandidateDetails()">Overall</button>
<table>
// Here I am rendring the data
</table>
.html文件

 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);
 }
<button type="button" class="btn btn-primary" (click)="getFemaleCandidateDetails()">Overall</button>
<table>
// Here I am rendring the data
</table>
总体
//我在这里整理数据

您能提供一些代码让我们有个想法吗?您可能提交了导致页面刷新的表单。这可能是因为刷新了整个数据。如果您使用的是ngFor,请尝试添加trackByIndex选项,因为表格是页面正文中显示的唯一组件。如果是,则如果正文不够大,则它将始终滚动到顶部,因为它们在表格中不存在,并且当填充数据时,页面处于开始位置。您的表格是页面正文中显示的唯一组件箱。如果是,那么如果主体不够大,那么它将始终滚动到顶部,因为它们在表中不存在,并且当填充数据时,页面处于开始位置