角度div scrollTop属性未设置

时间:2018-09-28 18:13:36

标签: html angular scrolltop

在我的角度应用程序中,我有一个显示表格的div。表格会根据我们添加的行动态增加其高度。当表格以新行更新后,我需要在div的末尾显示滚动条。

我在DIV中添加了一个参考元素,并在组件文件中使用它来设置scrollTop。 但是scrollTop没有设置设置。

<div #scrollDiv >
<table>
</table>
</div>

@ViewChild('scrollDiv') private myScrollDiv: ElementRef;

testUpdateTable() {
    this.myScrollDiv.nativeElement.scrollTop = this.myScrollDiv.nativeElement.height;
}

<button type="button" id="btn" class="btn-primary" (click)="testUpdateTable()" >Update List</button>  

如果直接在DIV上设置该属性,它确实可以工作,但是有一点我需要清除表,清除后会出现uncheckedexpression错误。

这有效:

<div #scrollDiv [scrollTop]="scrollDiv.scrollHeight">
<table>
</table>
</div>

0 个答案:

没有答案