Angular 2, how to make a href point to a local div?

I want to create a href jumps to a specific div once clicked.

Currently I am using a function:

<button class="btn btn-default" (click)="gotoDiv()">Go to div</button>
...
gotoDiv(): void {
     window.location.href = window.location.href + "#someDiv";
}

But I don’t want to put html id in my service. I’d like to have something like this:

<a href="#someDiv" target="_self">Go to some div</a>
<div id="someDiv"></div>

But this code reloads the page and doesn’t lead me to the div. Thanks in advance.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

That is currently not supported.

For more details see the discussion in https://github.com/angular/angular/issues/6595