Angularjs $ anchorScroll sometimes refreshes the whole page

I have an application with angularjs routing, but in some ways I want to scroll to some specific div, and I use anchorScroll, but sometimes (not all times) it refreshes the whole page, even stopping the event from spreading. Has anyone had this problem?

$scope.redirectTodiv = function(divname,event) { event.stopPropagation(); event.preventDefault(); $location.hash(divname); $anchorScroll(); }; 
+2
source share
2 answers

try it

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

To provide one-click navigation, you need to combine $ location.hash () $ anchorScroll and set the routeProvider reloadOnSearch property to false, i.e. in your controller code:

  $location.hash("editor"); $anchorScroll(); 

Your route provider:

 $routeProvider.when("/masters/voucher", { templateUrl: "views/card/voucher.html", reloadOnSearch: false }) 
0
source

All Articles