I am working on an Angular 5 project. In my project I have chat box like element. I am listing the comments in a ul
, its height is fixed with overflow-y: auto
. Like a standard chat box I have to show the very bottom of this scrollable ul
. So when a new comment is added it will be coming at the bottom of the ul
and I have to scroll to the bottom. In order to achieve this I am binding the scrollTop
property of this ul
to the scrollHeight
as follows,
<ul class="comment-list" #commentEl [scrollTop]="commentEl.scrollHeight">
<li *ngFor="let comment of comments">{{ comment }}</li>
</ul>
I am getting an error ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '851'. Current value: '0'
while initializing this component and destroying this component. How can I fix this issue?