在angularJS中实现返回前一页

  1. html  
  2.   <script src="lib/angular/angular-1.4.9/angular.js"></script>  
  3.   <script src="lib/angular/angular-ui-router.min.js"></script>  
  4. app  
  5.     angular.module('ConsoleUIApp', ['ui.router','ui.bootstrap'])  
  6.         .config(function ($stateProvider, $urlRouterProvider, $httpProvider) {  
  7.   
  8.             // For any unmatched url, redirect to /state1  
  9.             $urlRouterProvider.otherwise("/home");  
  10.   
  11.             $stateProvider  
  12.                 .state('home', {  
  13.                     url: "/home",  
  14.                     templateUrl: "views/home.html",  
  15.                     controller: 'HomeCtrl'  
  16.                 })  
  17.                 .state('testing', {  
  18.                     url: "/testing",  
  19.                     templateUrl: "views/testing.html",  
  20.                     controller: 'TestingCtrl'  
  21.                 })  
  22.         })  
  23.   
  24.         .run(function($rootScope, growl, $state, $stateParams) {  
  25.             $rootScope.$state = $state;  
  26.             $rootScope.$stateParams = $stateParams;  
  27.             $rootScope.$on("$stateChangeSuccess",  function(event, toState, toParams, fromState, fromParams) {  
  28.                 // to be used for back button //won't work when page is reloaded.  
  29.                 $rootScope.previousState_name = fromState.name;  
  30.                 $rootScope.previousState_params = fromParams;  
  31.             });  
  32.             //back button function called from back button's ng-click="back()"  
  33.             $rootScope.back = function() {//实现返回的函数  
  34.                 $state.go($rootScope.previousState_name,$rootScope.previousState_params);  
  35.             };  
  36.         });  
  37. controller:  
  38.     $scope.sub = function(addRode) {  
  39.     $rootScope.back()//直接使用  
  40.     }  

猜你喜欢

转载自blog.csdn.net/u013184759/article/details/54971582
今日推荐