11import {
2+ AfterContentInit ,
23 Component ,
3- ElementRef ,
4+ Input ,
45 NgZone ,
5- AfterContentInit ,
66 OnChanges ,
77 OnDestroy ,
8- OnInit ,
98 SimpleChanges ,
109 ViewEncapsulation ,
11- Input ,
10+ ViewChild ,
1211} from '@angular/core' ;
1312import * as Handsontable from 'handsontable-pro' ;
1413import { HotTableRegisterer } from './hot-table-registerer.service' ;
@@ -18,14 +17,15 @@ import { HotColumnComponent } from './hot-column.component';
1817@Component ( {
1918 // tslint:disable-next-line
2019 selector : 'hot-table' ,
21- template : '' ,
20+ template : '<div #container [id]="hotId"></div> ' ,
2221 encapsulation : ViewEncapsulation . None ,
2322 providers : [ HotTableRegisterer , HotSettingsResolver ] ,
2423} )
2524
26- export class HotTableComponent implements AfterContentInit , OnChanges , OnDestroy , OnInit {
25+ export class HotTableComponent implements AfterContentInit , OnChanges , OnDestroy {
26+ @ViewChild ( 'container' ) public container ;
27+
2728 private hotInstance : Handsontable ;
28- private container : HTMLDivElement ;
2929 private columnsComponents : HotColumnComponent [ ] = [ ] ;
3030 // component inputs
3131 @Input ( ) settings : Handsontable . GridSettings ;
@@ -308,22 +308,11 @@ export class HotTableComponent implements AfterContentInit, OnChanges, OnDestroy
308308 @Input ( ) hiddenRow : ( row : number ) => void ;
309309
310310 constructor (
311- private el : ElementRef ,
312311 private _ngZone : NgZone ,
313312 private _hotTableRegisterer : HotTableRegisterer ,
314- private _hotSettingResolver : HotSettingsResolver
313+ private _hotSettingResolver : HotSettingsResolver ,
315314 ) { }
316315
317- ngOnInit ( ) : void {
318- this . container = document . createElement ( 'div' ) ;
319-
320- if ( this . hotId ) {
321- this . container . id = this . hotId ;
322- }
323-
324- this . el . nativeElement . appendChild ( this . container ) ;
325- }
326-
327316 ngAfterContentInit ( ) : void {
328317 const options : Handsontable . GridSettings = this . _hotSettingResolver . mergeSettings ( this ) ;
329318
@@ -338,7 +327,7 @@ export class HotTableComponent implements AfterContentInit, OnChanges, OnDestroy
338327 }
339328
340329 this . _ngZone . runOutsideAngular ( ( ) => {
341- this . hotInstance = new Handsontable ( this . container , options ) ;
330+ this . hotInstance = new Handsontable ( this . container . nativeElement , options ) ;
342331
343332 if ( this . hotId ) {
344333 this . _hotTableRegisterer . registerInstance ( this . hotId , this . hotInstance ) ;
@@ -358,14 +347,13 @@ export class HotTableComponent implements AfterContentInit, OnChanges, OnDestroy
358347 }
359348
360349 ngOnDestroy ( ) : void {
361- this . hotInstance . destroy ( ) ;
350+ this . _ngZone . runOutsideAngular ( ( ) => {
351+ this . hotInstance . destroy ( ) ;
352+ } ) ;
362353
363354 if ( this . hotId ) {
364355 this . _hotTableRegisterer . removeInstance ( this . hotId ) ;
365356 }
366-
367- this . el . nativeElement . removeChild ( this . container ) ;
368- this . container = void 0 ;
369357 }
370358
371359 updateHotTable ( newSettings : Handsontable . GridSettings ) : void {
0 commit comments