My question is: how can I still update the [scrolltop] after the check without getting the error?
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for 'scrollTop': '260'. Current value: '300'.
I have a variable where I push data in and because of that the variable string gets longer and longer and so the div gets bigger and I want to be always at the bottom of the divbox
component.html:
<div #logbox [scrollTop]="content.length === 0 ? 0 : logbox.scrollHeight" class="logbox">
{{content}}
<div *ngIf="!content" style="width: 100%; text-align: center; margin: 50px">No logs available</div>
</div>
component.css:
.logbox{
font-family: monospace;
overflow: hidden auto;
overflow-wrap:break-word;
white-space:pre-wrap;
height: 100%;
}
component.ts
export class LogboxComponent implements OnInit {
constructor() { }
@Input() content:string;
ngOnInit(): void {
}
}