@@ -197,6 +197,35 @@ describe('IgxForOf directive -', () => {
197197 horizontalScroller = fix . nativeElement . querySelector ( 'igx-horizontal-virtual-helper' ) ;
198198 } ) ;
199199
200+ it ( 'should reset scroll position if component is destroyed and recreated.' , async ( ) => {
201+ let scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
202+ expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
203+ expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
204+
205+ fix . componentInstance . scrollTop ( 500 ) ;
206+ fix . detectChanges ( ) ;
207+ await wait ( ) ;
208+ expect ( scrollComponent . scrollAmount ) . toBe ( 500 ) ;
209+
210+ fix . componentInstance . exists = false ;
211+ fix . detectChanges ( ) ;
212+ await wait ( ) ;
213+
214+ expect ( scrollComponent . destroyed ) . toBeTruthy ( ) ;
215+
216+ fix . componentInstance . exists = true ;
217+ fix . detectChanges ( ) ;
218+ await wait ( ) ;
219+
220+ scrollComponent = fix . debugElement . query ( By . css ( VERTICAL_SCROLLER ) ) . componentInstance ;
221+ expect ( scrollComponent . scrollAmount ) . toBe ( 0 ) ;
222+ expect ( scrollComponent . destroyed ) . toBeFalsy ( ) ;
223+
224+ displayContainer = fix . nativeElement . querySelector ( DISPLAY_CONTAINER ) ;
225+ const firstInnerDisplayContainer = displayContainer . children [ 0 ] ;
226+ expect ( firstInnerDisplayContainer . children [ 0 ] . textContent ) . toBe ( '0' ) ;
227+ } ) ;
228+
200229 it ( 'should initialize directive with vertical virtualization' , async ( ) => {
201230 expect ( displayContainer ) . not . toBeNull ( ) ;
202231 expect ( verticalScroller ) . not . toBeNull ( ) ;
@@ -1252,10 +1281,10 @@ export class VirtualComponent {
12521281 public cols = [ ] ;
12531282 public data = [ ] ;
12541283
1255- @ViewChild ( 'container' , { read : ViewContainerRef , static : true } )
1284+ @ViewChild ( 'container' , { read : ViewContainerRef , static : false } )
12561285 public container : ViewContainerRef ;
12571286
1258- @ViewChild ( 'scrollContainer' , { read : TestIgxForOfDirective , static : true } )
1287+ @ViewChild ( 'scrollContainer' , { read : TestIgxForOfDirective , static : false } )
12591288 public parentVirtDir : TestIgxForOfDirective < any > ;
12601289
12611290 @ViewChildren ( 'childContainer' , { read : TestIgxForOfDirective } )
@@ -1299,7 +1328,7 @@ export class VirtualComponent {
12991328/** Only vertically virtualized component */
13001329@Component ( {
13011330 template : `
1302- <div #container [style.width]='width' [style.height]='height'>
1331+ <div *ngIf='exists' #container [style.width]='width' [style.height]='height'>
13031332 <ng-template #scrollContainer igxForTest let-rowData [igxForOf]="data"
13041333 [igxForScrollOrientation]="'vertical'"
13051334 [igxForContainerSize]='height'
@@ -1327,6 +1356,7 @@ export class VerticalVirtualComponent extends VirtualComponent {
13271356 ] ;
13281357 public data = [ ] ;
13291358 public itemSize = '50px' ;
1359+ public exists = true ;
13301360}
13311361
13321362/** Only horizontally virtualized component */
0 commit comments