Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit 716f860

Browse files
committed
Missed a change or two
1 parent f604312 commit 716f860

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/NgGrid.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MyAppComponent {
3737
'sizex': 0,
3838
'sizey': 0
3939
}
40-
private curItemCheck:number = 1;
40+
private curItemCheck:number = 0;
4141
private itemPositions: Array<any> = [];
4242

4343
get itemCheck() { return this.curItemCheck; }
@@ -51,7 +51,7 @@ class MyAppComponent {
5151
}
5252

5353
removeBox() {
54-
this.boxes.splice(this.curItemCheck, 1);
54+
if (this.boxes[this.curItemCheck]) this.boxes.splice(this.curItemCheck, 1);
5555
}
5656

5757
updateItem(index: number, pos: { col: number, row: number, sizex: number, sizey: number }) {

0 commit comments

Comments
 (0)