我在获取数据时添加了一个加载。在我的视图列表中有分页和页面大小。所以我的问题是每当我尝试更改页面大小并在加载后立即移动到其他页面时,它不会移动到顶部。我在加载后已经添加了this.document.body.scrollTop = 0;
,但它不起作用。
这些是我获取数据的代码:
`getProducts() {
this.productService
.getProducts(this.args)
.subscribe(
data => {
this.data = data;
this.loadingService.hide();
this.document.body.scrollTop = 0;
},
(error) =>
console.log(error);
}
);
}`
试试这样:
component.html
<button class="btn btn-info" (click)="goTop()">goTop</button>
component.ts
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
export class Component {
constructor(
@Inject(DOCUMENT) private document: Document
) {}
goTop() {
this.document.body.scrollTop = 0;
}
}
import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
@Component({...})
export class MyPage{
@ViewChild(Content) content: Content;
添加到内部订阅
this.content.scrollToTop();
参考; qazxsw poi
在ngOnit中使用http://ionicframework.com/docs/api/components/content/Content/。所以看起来应该是这样的
window.scrollTo(0,0);