angular2-grid icon indicating copy to clipboard operation
angular2-grid copied to clipboard

grid triggers change detection in angular2

Open MortenSkjoldager opened this issue 8 years ago • 6 comments

Hi got the following markup,

<div class="grid-dashboard">
    <div [ngGrid]="gridConfig">
        <div *ngFor="let widget of widgets" [(ngGridItem)]="widget.config">
            <div class="grid-item-header" [hidden]="widget.config.hideWidgetHeader != null && widget.config.hideWidgetHeader">
                <span class="grid-item-header-name">{{widget.name}}</span>
            </div>
            <div class="grid-item-content">
                <dynamic-component [model]="widget.component"></dynamic-component>
            </div>
        </div>
    </div>
</div>
ngOnInit() : void {
        this.gridConfig = {
            'draggable': this.dashboardEditMode,    
            'resizable': this.dashboardEditMode,
            'cascade': 'up',  
        };

        this.widgets = [];
        for (let component of this.model.components) {
            this.widgets.push({
                name: component.config.displayName,
                config: {
                    sizex: component.config.sizeX,
                    sizey: component.config.sizeY,
                    col: component.config.col,
                    row: component.config.row
                },
                component: component,
                components: component.components
            });
        }
    }

Whenever i move the mouse on the screen i see all interpolutions of {{something()}} going bananas. (I've added console.log() events in there to see it happening). When i disable the grid it doesn't behave like that. Tried with the latest 2.0.1 with angular 2.4.4

MortenSkjoldager avatar Feb 02 '17 10:02 MortenSkjoldager

BTW i tried to do a plunker, but i failed :( https://plnkr.co/edit/KxPusbL9IJLCDIpxZhxf?p=catalogue

MortenSkjoldager avatar Feb 02 '17 10:02 MortenSkjoldager

I've created a root plunker here: https://plnkr.co/edit/3m8ost Give that a try and see if you can replicate the issue :)

BTMorton avatar Mar 05 '17 14:03 BTMorton

Hi BTMorton, funny you should update it yesterday. I've been away for this in a month and just got back to it. I've done a fork here:

https://plnkr.co/edit/yPGKbkx9lTKwmvJcG21e?p=preview

I have added a single function in app.ts that will do a console.log and calling that function in my template. It goes crazy whenever i move the mouse. Any way to avoid that?

MortenSkjoldager avatar Mar 06 '17 10:03 MortenSkjoldager

No update on this BTMorton?

MortenSkjoldager avatar Apr 05 '17 13:04 MortenSkjoldager

I don't know. Best guess is that it's causing the angular change detection routine to run because it's bound the mouse move events. I don't know what would cause it otherwise. I can try to investigate further, but my knowledge of the Angular 2+ change detection algorithms is limited at best.

BTMorton avatar May 05 '17 23:05 BTMorton

I guess it should only bind the move events when there's actually something that should move. Usually the configuration properties are set to false which means that i cant move or resize anything. So it should subscribe/unsubscribe on request.

MortenSkjoldager avatar May 08 '17 08:05 MortenSkjoldager