在angularJS中实现返回前一页

前端之家收集整理的这篇文章主要介绍了在angularJS中实现返回前一页前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 
 
html
  <script src="lib/angular/angular-1.4.9/angular.js"></script>
  <script src="lib/angular/angular-ui-router.min.js"></script>
app
    angular.module('ConsoleUIApp',['ui.router','ui.bootstrap'])
        .config(function ($stateProvider,$urlRouterProvider,$httpProvider) {

            // For any unmatched url,redirect to /state1
            $urlRouterProvider.otherwise("/home");

            $stateProvider
                .state('home',{
                    url: "/home",templateUrl: "views/home.html",controller: 'HomeCtrl'
                })
                .state('testing',{
                    url: "/testing",templateUrl: "views/testing.html",controller: 'TestingCtrl'
                })
        })

        .run(function($rootScope,growl,$state,$stateParams) {
            $rootScope.$state = $state;
            $rootScope.$stateParams = $stateParams;
            $rootScope.$on("$stateChangeSuccess",function(event,toState,toParams,fromState,fromParams) {
                // to be used for back button //won't work when page is reloaded.
                $rootScope.prevIoUsState_name = fromState.name;
                $rootScope.prevIoUsState_params = fromParams;
            });
            //back button function called from back button's ng-click="back()"
            $rootScope.back = function() {//实现返回的函数
                $state.go($rootScope.prevIoUsState_name,$rootScope.prevIoUsState_params);
            };
        });
controller:
	$scope.sub = function(addRode) {
	$rootScope.back()//直接使用
	}




https://github.com/angular-ui/ui-router/issues/92

猜你在找的Angularjs相关文章