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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -