-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (44 loc) · 1.59 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html ng-app="HistoryTest">
<head>
<script src="jquery-2.0.0.js"></script>
<script src="angular.js"></script>
<script>
angular.module('HistoryTest', []).
config(function ($locationProvider) {
$locationProvider.html5Mode(true);
});
function HistoryCtrl($scope, $location, $rootScope) {
'use strict';
$scope.message = 'Enter state message';
$scope.attempt = -1;
$scope.pushState = function (ev) {
ev.preventDefault();
$scope.attempt += 1;
$location.url('/history-test-' + $scope.attempt, false, $scope.message);
};
$rootScope.$on('$locationChangeSuccess', function (event, url, oldUrl, state) {
$scope.stateMessage = state; // Hackish access to 'pop-ed' state.
});
}
// window.onpopstate = function (ev) {
// var $smsg = $('#statemsg');
// if (ev.state)
// $smsg.val(ev.state);
// else
// $smsg.val('');
// }
</script>
<title>Angular history test</title>
</head>
<body>
<div ng-controller="HistoryCtrl">
<label for="msg">Message:</label>
<input id="msg" type="text" ng-model="message" />
<br />
<a ng-click="pushState($event)" href="/history" target="_self">Push state with current message</a> <br />
<label for="statemsg">State message:</label>
<input id="statemsg" type="text" value="{{ stateMessage }}" disabled/>
</div>
</body>
</html>