var app = app.module('myApp', ['ngAnimate', 'ui.router']);
app.constant('referrers', []);
app.config(function ($stateProvider, $urlRouterProvider, referrers) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/',
templateUrl: 'views/list.html',
onExit: function ($state) {
referrers.push({name: $state.current.name, params: $state.params});
}
})
.state('profile', {
url: '/profile',
templateUrl: 'views/list.html',
onExit: function ($state) {
referrers.push({name: $state.current.name, params: $state.params});
}
})
});
app.controller('myController', ['$scope', '$state', 'referrers', '$timeout', function ($scope, $state, referrers, $timeout) {
$scope.isBack = false;
$scope.viewBack = function () {
if (referrers.length == 0) return false;
$scope.isBack = true;
// 删除记录并返回页面
var prev = referrers.pop();
$state.go(prev.name, prev.params);
$timeout(function () {
referrers.pop();
$scope.isBack = false;
}, 350);
};
}])
onExit: function ($state, yourService) { }