Good memory is better than bad writing ... As a note, the first to start from anchor Scroll, a cup of coffee time can be read, long do not see:)
- $anchorScroll () to jump to the definition ID;
- The hash () method of the $location object replaces the current URL as a hash key;
- $anchorScroll () reads and jumps to the ID.
In the following simple example, here is the output:
Source index.html--11 line, marked with the Jump ID:
1 <!DOCTYPE HTML>2 <HTMLNg-app= "App">3 <Head>4 <Scriptsrc= "Angular.min.js"></Script>5 <Scriptsrc= "App.js"></Script>6 <MetaCharSet= "Utf-8">7 </Head>8 9 <BodyNg-controller= "Mockcontroller">Ten <Buttonng-repeat= "(key, value) in numbers"Ng-click= "jumper (key)">{{Key}}</Button> One <Divng-repeat= "(key, value) in numbers"ID= "{{key}}"> A <H1>{{Key}}</H1> - <ol> - <ulng-repeat= "Item in value">{{Item}}</ul> the </ol> - </Div> - </Body> - </HTML>
App.js
1 varDEMOAPP = Angular.module ("app",[])2. Controller ("Mockcontroller",3 function($scope, $location, $anchorScroll) {4$scope. Numbers = {5"Natural number": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"],6"Prime": ["2", "3", "5", "7", "11", "13", "17", "19", "23", "29"]7 };8 9$scope. Jumper =function(key) {Ten $location. hash (key); One $anchorScroll (); A } -});
ANGULARJS Module Learning 1 Anchor Scroll