我有以下代码
$scope.scrollTo = function(id) {
alog($location.hash());
var toScrollId = "anchor" + id;
if($location.hash() !== toScrollId){
alog(" hash is not equal")
$location.hash(toScrollId);
}else{
alog(" hash is equal")
$anchorScroll();
}
};
和 html 看起来像
<button ng-click="scrollTo(raceid)">GO TO THIS</button>
<div ng-repeat="race in races" id="{{ 'anchor' + race.raceId}}">
</div>
但滚动总是到页面顶部。我做错了什么?