I want to scroll down to a section when the page loads in Angular on some condition.
Please note: I want to scroll down without clicking on anything(i.e, on ngOnInit
).
I tried this: in my component.html file
<div #sectionSubscribe>
HTML...
</div>
in my component.ts file
ngOnInit(){
this.scrollToSubscribe(sectionSubscribe);
}
scrollToSubscribe($element){
$element.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
});
}
But it doesn't allow me to do so. Please help