angularjs - anchorScroll not working, going to top of page -
i have below code
$scope.scrollto = function(id) { alog($location.hash()); var toscrollid = "anchor" + id; if($location.hash() !== toscrollid){ alog(" hash not equal") $location.hash(toscrollid); }else{ alog(" hash equal") $anchorscroll(); } }; and html looks like
<button ng-click="scrollto(raceid)">go this</button> <div ng-repeat="race in races" id="{{ 'anchor' + race.raceid}}"> </div> but scroll goes top of page. doing wrongly?
your ng-repeat assigning id parent element (in case, races div) might need modify first:
<div ng-repeat="race in races" id="races"> <div id="{{ 'anchor' + race.raceid }}">some race</div> </div>
Comments
Post a Comment