I start a new project using Angular
.html file:
<a (click)="go()">toto</a>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam iaculis ex
porttitor semper iaculis. Nam dapibus erat interdum, scelerisque magna et, finibus sapien. Aliquam tempus porta ante id rhoncus. Cras sit amet consequat tellus, at malesuada tellus. Vivamus et augue dolor. In consequat pretium massa in imperdiet. Donec sapien nulla, commodo sed est et, lacinia sodales augue. Curabitur sed neque vel quam consequat blandit. Curabitur rutrum commodo pretium. Maecenas posuere, nibh a ultricies laoreet, orci...
Nullam pretium tellus odio. Donec hendrerit odio vel pellentesque imperdiet. Integer eget auctor magna, ut placerat tortor. Donec ut ante fermentum, molestie augue fringilla, ornare nunc.</div>
<div [hidden]="!show">
<h2 id="step1">titi</h2>
</div>
.ts file:
show : boolean = false
go(){
this.show = true
document.getElementById("step1").scrollIntoView({behavior : "smooth"})
}
However, I encounter an error when clicking on the anchor tag for the first time :
Cannot read property scrollIntoView of null
What steps should be taken to resolve this issue?