Reputation: 185
I have a form where I am adding objects to An array, then I am giving the user a preview of the created objects.
I am looping the array with a *ngFor and each element added to the bottom of the screen. My goal that after each element was added there will be an auto scroll to the bottom of the page
Currently i am using a setTimeOut function, but i was wondering is there a better way?
this.createdAppointments.push(appointmentFormValues);
setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight || document.documentElement.scrollHeight);
}, 1);
Upvotes: 0
Views: 278
Reputation: 191
You can call scrollIntoView method on newly added items, see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
Upvotes: 1