@@ -91,14 +91,20 @@ export class MdTabBody implements OnInit, AfterViewChecked {
9191  /** The portal host inside of this container into which the tab body content will be loaded. */ 
9292  @ViewChild ( PortalHostDirective )  _portalHost : PortalHostDirective ; 
9393
94+   /** Element wrapping the tab's content. */ 
95+   @ViewChild ( 'content' )  _contentElement : ElementRef ; 
96+ 
9497  /** Event emitted when the tab begins to animate towards the center as the active tab. */ 
9598  @Output ( )  onCentering : EventEmitter < number >  =  new  EventEmitter < number > ( ) ; 
9699
97100  /** Event emitted when the tab completes its animation towards the center. */ 
98101  @Output ( )  onCentered : EventEmitter < void >  =  new  EventEmitter < void > ( true ) ; 
99102
100103  /** The tab body content to display. */ 
101-   @Input ( 'content' )  _content : TemplatePortal < any > ; 
104+   @Input ( 'content' )  _contentPortal : TemplatePortal < any > ; 
105+ 
106+   /** Scroll position of the tab before the user switched away. */ 
107+   private  _lastScrollPosition  =  0 ; 
102108
103109  /** The shifted index position of the tab body, where zero represents the active center tab. */ 
104110  _position : MdTabBodyPositionState ; 
@@ -146,7 +152,8 @@ export class MdTabBody implements OnInit, AfterViewChecked {
146152   */ 
147153  ngAfterViewChecked ( )  { 
148154    if  ( this . _isCenterPosition ( this . _position )  &&  ! this . _portalHost . hasAttached ( ) )  { 
149-       this . _portalHost . attach ( this . _content ) ; 
155+       this . _portalHost . attach ( this . _contentPortal ) ; 
156+       this . _contentElement . nativeElement . scrollTop  =  this . _lastScrollPosition ; 
150157    } 
151158  } 
152159
@@ -159,6 +166,7 @@ export class MdTabBody implements OnInit, AfterViewChecked {
159166  _onTranslateTabComplete ( e : AnimationEvent )  { 
160167    // If the end state is that the tab is not centered, then detach the content. 
161168    if  ( ! this . _isCenterPosition ( e . toState )  &&  ! this . _isCenterPosition ( this . _position ) )  { 
169+       this . _lastScrollPosition  =  this . _contentElement . nativeElement . scrollTop  ||  0 ; 
162170      this . _portalHost . detach ( ) ; 
163171    } 
164172
@@ -176,7 +184,7 @@ export class MdTabBody implements OnInit, AfterViewChecked {
176184  /** Whether the provided position state is considered center, regardless of origin. */ 
177185  private  _isCenterPosition ( position : MdTabBodyPositionState | string ) : boolean  { 
178186    return  position  ==  'center'  || 
179-         position  ==  'left-origin-center'  || 
180-         position  ==  'right-origin-center' ; 
187+             position  ==  'left-origin-center'  || 
188+             position  ==  'right-origin-center' ; 
181189  } 
182190} 
0 commit comments