简体   繁体   中英

AngularJS and link redirection with anchor

I want to use angularJS to scroll smoothly directly to the section specified in the link. For example, starting link:

https://stackoverflow.com/#footer

This will redirect me to the footer of that page instantly. So I want to create an angular controller to manage this situation. My Idea is to create an angular controller something like this:

angular.element(document).ready(function () {
    var target = $location.hash();
    .... (function to go smoothly to that point) ....
}

The problem is that the hash() function returns an empty string. Where is the problem?

Don't reinvent the wheel, you can use one of this two good library:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM