Angular-gridster2: Remove item: Cannot read property 'hasAttribute' of null

Created on 22 Mar 2018  路  2Comments  路  Source: tiberiuzuld/angular-gridster2

Hello, I encountered an error when modifying array of grid items. I remove an item on button click:

    remove(item: GridsterItem, row: DashboardGridRow) {
        row.items = row.items.filter(rowItem => rowItem !== item);
    }
<div class="row" *ngFor="let row of dashboard.rows">
        <div class="col">
            <gridster class="dashboard-row-grid" [options]="options">
                <gridster-item #itemComponent class="dashboard-grid-item" [item]="item"
                               *ngFor="let item of row.items">
                    <button type="button" class="btn btn-warning" (click)="remove(item, row)">
                        Remove
                    </button>
                </gridster-item>
            </gridster>
        </div>
    </div>

When I click the button, item gets removed, but I always get an error in the console:

ERROR TypeError: Cannot read property 'hasAttribute' of null
    at Function.GridsterUtils.checkContentClass (gridsterUtils.service.js:65)
    at Function.GridsterUtils.checkContentClass (gridsterUtils.service.js:69)
    at Function.GridsterUtils.checkContentClass (gridsterUtils.service.js:69)
    at Function.GridsterUtils.checkContentClassForEmptyCellClickEvent (gridsterUtils.service.js:58)
    at GridsterEmptyCell.emptyCellClickCb (gridsterEmptyCell.service.js:59)
    at HTMLUnknownElement.eval (platform-browser.js:2628)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4740)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)

Any ideas? Should I do something extra?

bug

Most helpful comment

Yeah do stop event propagation, it checks for drag and you removed the element ...
Maybe should add a check in the code also.

But for now add a stopEventPropagation and should work.

All 2 comments

Yeah do stop event propagation, it checks for drag and you removed the element ...
Maybe should add a check in the code also.

But for now add a stopEventPropagation and should work.

The fix will be available in version 5.0.0 coming soon.

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CollinGraf314 picture CollinGraf314  路  3Comments

tiberiuzuld picture tiberiuzuld  路  3Comments

JohnxAss picture JohnxAss  路  5Comments

Vojislav-Vukovic picture Vojislav-Vukovic  路  4Comments

aren5a picture aren5a  路  5Comments