1

I have a simple $http function in my Angular app that fetches/updates some data on the view when the user clicks a button. Here is the function:

function getData() {
    return $http({
        method: 'GET',
        url: '/some_endpoint.json',
        params: params
    }).then(function(resp){
        if(resp && resp.data) {
            $scope.data = resp.data;
            // Do some other stuff here
        }
    });
}

I've noticed that whenever this function is called, the page scrolls back to the top. I want to know how to prevent this undesirable behavior.

I've already tried all the solutions proposed in this question, but none of them have any effect. Additionally, I'd like to avoid having my $http function or its wrapper function getData return false, as suggested here as that would prevent me from chaining additional promise functions to it.

Daniel Bonnell
  • 4,817
  • 9
  • 48
  • 88
  • Could you give the view/HTML code as well? – nikjohn Sep 09 '16 at 15:25
  • 1
    It's just a button with an `ng-click` attribute on it that updates a chart. I don't think the HTML is relevant at all. For what it's worth, I have this "problem" with every single `$http` call in the entire app. – Daniel Bonnell Sep 09 '16 at 15:33

0 Answers0