AngularJS 如何完成在本页的id跳转

html:在需要跳转的地方添加scrollTo()参数是跳转的id.


Scroll to #foo

This is #foo

JavaScript: 在你的控制器完成你的跳转操作.(这需要声明$location, $anchorScroll)

app.controller('MainCtrl', function($scope, $location, $anchorScroll, $routeParams) {
  $scope.scrollTo = function(id) {
     $location.hash(id);
     $anchorScroll();
  }
});

你可能感兴趣的:(AngularJS 如何完成在本页的id跳转)