在angularJS中实现返回前一页


html
  
  
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()//直接使用
	}


 在用上面的方法时,可以直接试试

history.go(-1)

如果不管用再用上面的方法


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

你可能感兴趣的:(AngularJS知识点汇总)