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

ngCell element disconnected from DOM during $compile causes inheritedData() problems

Open ekaufman opened this issue 13 years ago • 1 comments

I found this issue trying to use the built in $pristine, $invalid and $dirty handling in angular's ngForm and ngModel. If you customize the cellTemplate to be an editor using ngModel the $dirty, $invalid, etc states are never updated in the form.

The issue is caused because the ngCell directive compiles the cell template before it's attached to the DOM. This means that anything that template does that depends on angular's inheritedData() will be broken.

Here's a plunk illustrating the issue. http://plnkr.co/edit/Mt2wccRpmn6aEemSqfTf

I've also included in the plunk a patched ng-grid.js that has the fix I've been using, you can swap that in to see how it should behave.

Essentially, I changed the order of this:

                   var cellElement = $compile(html)($scope);

                    if ($scope.enableCellSelection && cellElement[0].className.indexOf('ngSelectionCell') === -1) {
                        cellElement[0].setAttribute('tabindex', 0);
                        cellElement.addClass('ngCellElement');
                    }

                    iElement.append(cellElement);

To:

                    var cellElement = $(html);
                    iElement.append(cellElement);
                    $compile(cellElement)($scope);

                    if ($scope.enableCellSelection && cellElement[0].className.indexOf('ngSelectionCell') === -1) {
                        cellElement[0].setAttribute('tabindex', 0);
                        cellElement.addClass('ngCellElement');
                    }

ekaufman avatar Oct 16 '13 22:10 ekaufman

Closed via #1010

roblarsen avatar Mar 22 '14 21:03 roblarsen