angular 路由处于活动状态时如何制作正确的锚标记

How to make proper anchor tags when angular route is active

我正在尝试为模板设置一些锚标记,该模板由 angular route 修改并具有以下 url 方案:

main.html#/view/:name

我试图通过设置 target 属性来忽略 angular 的路由:

 <a target="_self" href="#some_anchor">Go to anchor</a>

然而,实际的 link 现在是 main.html#/some_anchor,省略 target=_self 不会改变任何东西。
然后我尝试使用

将 links 目标更改为实际当前 url
$location.path() + "/#some_anchor"

也不起作用(无论我是否设置 target 属性),我仍然收到 "Page not found" 错误。

我必须在同样的情况下解决这个问题:

在范围内定义函数:

$scope.scrollTo = function (id) {
    var old = $location.hash();
    $location.hash(id);
    $anchorScroll();
    $location.hash(old);
};

并这样称呼它:

<a href="" data-ng-click="scrollTo('anchor')">Scroll to anchor</a>