I'm trying to implement a scrollTo effect in AngularJS on an ng-click event, following the example in this Plunkr.
I'm trying to scroll to categoryhead, like so:
myApp.controller('FoodCtrl', function ($scope, $http, $location, $anchorScroll) {
//other stuff
$scope.loadFood = function(category) {
//other stuff
//Scroll category head to top of page
$scope.categoryhead = "#" + category;
$location.hash($scope.categoryhead);
$anchorScroll();
//Ajax load stuff
};
});
I have the value of $scope.categoryhead printing out in the template and can see that it is the correct ID for each element, but the window doesn't get scrolled. Am I doing something wrong in trying to pass the element ID to $anchorscroll()?