角度5:什么时候角度完成页面加载? [英] Angular5: When angular finished page loading?

查看:33
本文介绍了角度5:什么时候角度完成页面加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的angular5应用程序中,我使用的是表格。表中的数据来自后端。当表格第一次满载时,我想更改表格内的滚动位置。为此,我这样做:

ngAfterViewInit() {
    setTimeout(function () {
        const scroller = document.getElementById('list-container');
        scroller.scrollTop = amountTop; // amountTop is the calculated height, which represents the centre of the table 
    }, 500);
}

有没有比使用setTimeout()函数更好的处理DOM的方法?

api

您需要在setTimeout超时为0的情况下执行推荐答案调用成功时的顶部滚动代码,以便 代码在打勾后执行,即在数据绑定完成后

this.marketService.getBuyOrder(marketId, start, limit)
.subscribe(data => { 
    const buyOrders = data; 
    if (buyOrders.length > 0) { 
        this.bids = this.bids.concat(buyOrders); 
    } else { 
        this.loadMore = false; 
    } 
    this.cd.markForCheck();

    // The timeout is set to 0 to allow angular to bind the array to view
    setTimeout(function () {
        const scroller = document.getElementById('list-container');
        scroller.scrollTop = amountTop;
    }, 0);
}, (err: HttpErrorResponse) => { Helper.handleError(err, this.alertService); });

这篇关于角度5:什么时候角度完成页面加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆