Files
ionic-framework/js/ext/angular/test/anchorScroll.html
Andy Joslin 4715a118e0 refactor($ionicScrollDelegate): make it a factory from current scope
BREAKING CHANGE: $ionicScrollDelegate no longer works globally; you must
create a new instance of each time you use it.  The actual methods on
each instance of $ionicScrollDelegate are the same, however.

Change your code from this:

```js
function MyController($scope, $ionicScrollDelegate) {
  $scope.scrollTop = function() {
    $ionicScrollDelegate.scrollTop();
  };
}
```

To this:

```js
function MyController($scope, $ionicScrollDelegate) {
  var delegate = $ionicScrollDelegate($scope);
  $scope.scrollTop = function() {
    delegate.scrollTop();
  };
}
```
2014-03-17 07:21:20 -06:00

53 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html ng-app="ionic">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="stylesheet" href="../../../../dist/css/ionic.css" />
<script src="../../../../dist/js/ionic.bundle.js"></script>
</head>
<body>
<div ng-controller="MyCtrl">
<header class="bar bar-header bar-positive">
<div class="buttons">
<button class="button button-icon icon ion-clock" ng-click="doScroll()"></button>
</div>
<h1 class="title">Click the Clock to Get Stuck</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item ng-repeat="item in items"
item="item"
id="foo-{{item.id}}"
href="#/item/{{item.id}}">
Item {{ item.id }}
</ion-item>
</ion-list>
</ion-content>
</div>
<script>
function MyCtrl($scope, $location, $ionicScrollDelegate) {
var delegate = $ionicScrollDelegate($scope);
$scope.items = [];
for (var i=0; i < 100; i++) {
$scope.items.push({id:i});
}
$scope.doScroll = function() {
$location.hash('foo-50');
delegate.anchorScroll(true);
}
}
</script>
</body>
</html>