angularjs $anchorScroll sometimes refresh all page

I have an app with angularjs routing, but on some view i want to scroll to some specific div and i use anchorScroll but sometimes (not all times) it refresh all page even i stop event propagation. Did anyone had this issue?

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

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

 };

Answers:

Answer

Try like this

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

 };
Answer

The way to ensure navigation with one click is to combine $location.hash() $anchorScroll and setting routeProvider reloadOnSearch property to false i.e. In your controller code:

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

In your route provider:

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.