@@ -91,13 +91,15 @@ export class NgGrid {
9191 }
9292
9393 // Constructor
94- constructor ( private _differs : KeyValueDiffers , private _ngEl : ElementRef , private _renderer : Renderer , private _loader : DynamicComponentLoader ) {
94+ constructor ( private _differs : KeyValueDiffers , private _ngEl : ElementRef , private _renderer : Renderer , private _loader : DynamicComponentLoader ) { }
95+
96+ // Public methods
97+ public onInit ( ) {
9598 this . _renderer . setElementClass ( this . _ngEl , 'grid' , true ) ;
9699 if ( this . autoStyle ) this . _renderer . setElementStyle ( this . _ngEl , 'position' , 'relative' ) ;
97100 this . setConfig ( NgGrid . CONST_DEFAULT_CONFIG ) ;
98101 }
99102
100- // Public methods
101103 public setConfig ( config : any ) : void {
102104 var maxColRowChanged = false ;
103105 for ( var x in config ) {
@@ -211,13 +213,13 @@ export class NgGrid {
211213
212214 var colWidth : number = Math . floor ( maxWidth / this . _maxCols ) ;
213215 colWidth -= ( this . marginLeft + this . marginRight ) ;
214- this . colWidth = colWidth ;
216+ if ( colWidth > 0 ) this . colWidth = colWidth ;
215217 } else if ( this . _autoResize && this . _maxRows > 0 ) {
216218 var maxHeight : number = window . innerHeight ;
217219
218220 var rowHeight : number = Math . floor ( maxHeight / this . _maxRows ) ;
219221 rowHeight -= ( this . marginTop + this . marginBottom ) ;
220- this . rowHeight = rowHeight ;
222+ if ( rowHeight > 0 ) this . rowHeight = rowHeight ;
221223 }
222224
223225 for ( var x in this . _items ) {
@@ -277,13 +279,14 @@ export class NgGrid {
277279
278280 public removeItem ( ngItem : NgGridItem ) : void {
279281 this . _removeFromGrid ( ngItem ) ;
282+
280283 for ( var x in this . _items )
281284 if ( this . _items [ x ] == ngItem )
282285 this . _items . splice ( x , 1 ) ;
283286
284287 // Update position of all items
285- this . _updateSize ( ) ;
286288 this . _cascadeGrid ( ) ;
289+ this . _updateSize ( ) ;
287290 this . _items . forEach ( ( item ) => item . recalculateSelf ( ) ) ;
288291 }
289292
@@ -870,7 +873,7 @@ export class NgGrid {
870873 private _createPlaceholder ( pos : { col : number , row :number } , dims : { x : number , y : number } ) {
871874 var me = this ;
872875
873- this . _loader . loadNextToLocation ( ( < Type > NgGridPlaceholder ) , this . _items [ 0 ] . getElement ( ) ) . then ( componentRef => {
876+ this . _loader . loadNextToLocation ( ( < Type > NgGridPlaceholder ) , ( < any > this . _ngEl . parentView ) . _view . elementRefs [ this . _ngEl . boundElementIndex + 1 ] ) . then ( componentRef => {
874877 me . _placeholderRef = componentRef ;
875878 var placeholder = componentRef . instance ;
876879 // me._placeholder.setGrid(me);
@@ -1165,7 +1168,9 @@ class NgGridPlaceholder {
11651168 private _col : number ;
11661169 private _row : number ;
11671170
1168- constructor ( private _renderer : Renderer , private _ngEl : ElementRef , private _ngGrid : NgGrid ) {
1171+ constructor ( private _renderer : Renderer , private _ngEl : ElementRef , private _ngGrid : NgGrid ) { }
1172+
1173+ public onInit ( ) {
11691174 this . _renderer . setElementClass ( this . _ngEl , 'grid-placeholder' , true ) ;
11701175 if ( this . _ngGrid . autoStyle ) this . _renderer . setElementStyle ( this . _ngEl , 'position' , 'absolute' ) ;
11711176 }
0 commit comments