angularjs $ anchorScroll有时刷新所有页面

Joh*_*ohn 2 javascript angularjs

我有一个带有angularjs路由的应用程序,但在某些视图上我想滚动到一些特定的div我使用anchorScroll但有时(并非所有时间)它刷新所有页面甚至我停止事件传播.有人有这个问题吗?

 $scope.redirectTodiv = function(divname,event) {
    event.stopPropagation();  
    event.preventDefault();

    $location.hash(divname);
    $anchorScroll();

 };
Run Code Online (Sandbox Code Playgroud)

sol*_*4me 20

试试这样吧

$scope.redirectTodiv = function(divname,event) {
   var id = $location.hash();
    $location.hash(divname);
    $anchorScroll();
    $location.hash(id);

 };
Run Code Online (Sandbox Code Playgroud)