index.php
<html ng-app="myapp">
<div class="fixed-header" ng-controller="headerCtrl">
<a href="" ng-click="gotoAnchor(x)" ng-repeat="x in ['Home','About','Services','Contact','Blog']">
{{x}}
</a>
</div >
<div id="Home" class="anchor">
<div ng-controller="headerCtrl1">
Home Content
</div>
</div>
<div id="About" class="anchor">
About Content
</div>
<div id="Services" class="anchor">
Services Content
</div>
<div id="Contact" class="anchor">
Contact Content
</div>
<div id="Blog" class="anchor">
Blog Content
</div>
</html>
var app = angular.module('myapp', ['ngRoute']);
app.controller('headerCtrl', ['$anchorScroll', '$location', '$scope',
function($anchorScroll, $location, $scope) {
$scope.gotoAnchor = function(x) {
var newHash = x;
if ($location.hash() !== newHash) {
// set the $location.hash to `newHash` and
// $anchorScroll will automatically scroll to it
$location.hash(x);
} else {
// call $anchorScroll() explicitly,
// since $location.hash hasn't changed
$anchorScroll();
}
};
}]);
Sign up here with your email

ConversionConversion EmoticonEmoticon