@@ -557,9 +557,45 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
557
557
/**
558
558
* @ngdoc method
559
559
* @name $ionicHistory#goBack
560
+ * @param {number= } backCount Optional negative integer setting how many views to go
561
+ * back. By default it'll go back one view by using the value `-1`. To go back two
562
+ * views you would use `-2`. If the number goes farther back than the number of views
563
+ * in the current history's stack then it'll go to the first view in the current history's
564
+ * stack. If the number is zero or greater then it'll do nothing. It also does not
565
+ * cross history stacks, meaning it can only go as far back as the current history.
560
566
* @description Navigates the app to the back view, if a back view exists.
561
567
*/
562
- goBack : function ( ) {
568
+ goBack : function ( backCount ) {
569
+ if ( isDefined ( backCount ) && backCount !== - 1 ) {
570
+ if ( backCount > - 1 ) return ;
571
+
572
+ var currentHistory = viewHistory . histories [ this . currentHistoryId ( ) ] ;
573
+ var newCursor = currentHistory . cursor + backCount + 1 ;
574
+ if ( newCursor < 1 ) {
575
+ newCursor = 1 ;
576
+ }
577
+
578
+ currentHistory . cursor = newCursor ;
579
+ setNavViews ( currentHistory . stack [ newCursor ] . viewId ) ;
580
+
581
+ var cursor = newCursor - 1 ;
582
+ var clearStateIds = [ ] ;
583
+ var fwdView = getViewById ( currentHistory . stack [ cursor ] . forwardViewId ) ;
584
+ while ( fwdView ) {
585
+ clearStateIds . push ( fwdView . stateId || fwdView . viewId ) ;
586
+ cursor ++ ;
587
+ if ( cursor >= currentHistory . stack . length ) break ;
588
+ fwdView = getViewById ( currentHistory . stack [ cursor ] . forwardViewId ) ;
589
+ }
590
+
591
+ var self = this ;
592
+ if ( clearStateIds . length ) {
593
+ $timeout ( function ( ) {
594
+ self . clearCache ( clearStateIds ) ;
595
+ } , 600 ) ;
596
+ }
597
+ }
598
+
563
599
viewHistory . backView && viewHistory . backView . go ( ) ;
564
600
} ,
565
601
@@ -614,10 +650,10 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
614
650
* @description Removes all cached views within every {@link ionic.directive:ionNavView}.
615
651
* This both removes the view element from the DOM, and destroy it's scope.
616
652
*/
617
- clearCache : function ( ) {
653
+ clearCache : function ( stateIds ) {
618
654
$timeout ( function ( ) {
619
655
$ionicNavViewDelegate . _instances . forEach ( function ( instance ) {
620
- instance . clearCache ( ) ;
656
+ instance . clearCache ( stateIds ) ;
621
657
} ) ;
622
658
} ) ;
623
659
} ,
@@ -776,8 +812,8 @@ function($rootScope, $state, $location, $document, $ionicPlatform, $ionicHistory
776
812
}
777
813
} ) ;
778
814
779
- $rootScope . $ionicGoBack = function ( ) {
780
- $ionicHistory . goBack ( ) ;
815
+ $rootScope . $ionicGoBack = function ( backCount ) {
816
+ $ionicHistory . goBack ( backCount ) ;
781
817
} ;
782
818
783
819
// Set the document title when a new view is shown
0 commit comments